From 7b5d24e37f2a70aba7d4fb18560832099a473754 Mon Sep 17 00:00:00 2001 From: Daniil Goncharov Date: Tue, 12 Jan 2021 13:39:52 +0500 Subject: [PATCH] v0.10.0 (#30) v0.10.0 --- CMakeLists.txt | 2 +- doc/reference.md | 12 ++++++++++++ example/example_custom_name.cpp | 4 ++-- include/nameof.hpp | 22 +++++++++++++++------- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5efe259..3f82f8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.8) -project(nameof VERSION "0.9.5" LANGUAGES CXX) +project(nameof VERSION "0.10.0" LANGUAGES CXX) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(IS_TOPLEVEL_PROJECT TRUE) diff --git a/doc/reference.md b/doc/reference.md index bc25aed..d0a1a28 100644 --- a/doc/reference.md +++ b/doc/reference.md @@ -29,6 +29,18 @@ * To check is nameof_enum supported compiler use macro `NAMEOF_ENUM_SUPPORTED` or constexpr constant `nameof::is_nameof_enum_supported`.
If nameof_enum used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_ENUM_NO_CHECK_SUPPORT`. +* To add custom enum or type names see the [example](../example/example_custom_name.cpp). + +* To change the type of strings, use special macros: + + ```cpp + #include + #include + #define NAMEOF_USING_ALIAS_STRING using string = my_lib::String; + #define NAMEOF_USING_ALIAS_STRING_VIEW using string_view = my_lib::StringView; + #include + ``` + ## `NAMEOF` * Obtains simple (unqualified) name of variable, function, macro. diff --git a/example/example_custom_name.cpp b/example/example_custom_name.cpp index 003b1b6..0fb5e53 100644 --- a/example/example_custom_name.cpp +++ b/example/example_custom_name.cpp @@ -24,8 +24,8 @@ #include -enum class Color : int { RED = -10, BLUE = 0, GREEN = 10 }; -enum class Numbers : int { One, Two, Three }; +enum class Color { RED = -10, BLUE = 0, GREEN = 10 }; +enum class Numbers { One, Two, Three }; #if defined(NAMEOF_ENUM_SUPPORTED) // Сustom definitions of names for enum. diff --git a/include/nameof.hpp b/include/nameof.hpp index ba2d0cb..6c9f358 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -5,7 +5,7 @@ // | |\ | (_| | | | | | | __/ (_) | | | |____|_| |_| // |_| \_|\__,_|_| |_| |_|\___|\___/|_| \_____| // https://github.com/Neargye/nameof -// version 0.9.5 +// version 0.10.0 // // Licensed under the MIT License . // SPDX-License-Identifier: MIT @@ -33,8 +33,8 @@ #define NEARGYE_NAMEOF_HPP #define NAMEOF_VERSION_MAJOR 0 -#define NAMEOF_VERSION_MINOR 9 -#define NAMEOF_VERSION_PATCH 5 +#define NAMEOF_VERSION_MINOR 10 +#define NAMEOF_VERSION_PATCH 0 #include #include @@ -326,7 +326,7 @@ std::basic_ostream& operator<<(std::basic_ostream& o namespace detail { -constexpr string_view pretty_name(string_view name, bool remove_template_suffix = true) noexcept { +constexpr string_view pretty_name(string_view name, bool remove_suffix = true) noexcept { if (name.size() >= 1 && (name[0] == '"' || name[0] == '\'')) { return {}; // Narrow multibyte string literal. } else if (name.size() >= 2 && name[0] == 'R' && (name[1] == '"' || name[1] == '\'')) { @@ -392,7 +392,7 @@ constexpr string_view pretty_name(string_view name, bool remove_template_suffix break; } } - if (remove_template_suffix) { + if (remove_suffix) { name.remove_suffix(s); } @@ -567,9 +567,17 @@ constexpr auto values(std::index_sequence) noexcept { template > constexpr auto values() noexcept { static_assert(is_enum_v, "nameof::detail::values requires enum type."); - constexpr auto range_size = reflected_max_v - reflected_min_v + 1; + constexpr auto min = reflected_min_v; + constexpr auto max = reflected_max_v; + constexpr auto range_size = max - min + 1; static_assert(range_size > 0, "nameof::enum_range requires valid size."); static_assert(range_size < (std::numeric_limits::max)(), "nameof::enum_range requires valid size."); + if constexpr (cmp_less((std::numeric_limits::min)(), min) && !IsFlags) { + static_assert(!is_valid(0)>(), "nameof::enum_range detects enum value smaller than min range size."); + } + if constexpr (cmp_less(range_size, (std::numeric_limits::max)()) && !IsFlags) { + static_assert(!is_valid(range_size + 1)>(), "nameof::enum_range detects enum value larger than max range size."); + } return values>(std::make_index_sequence{}); } @@ -987,7 +995,7 @@ template #define NAMEOF_SHORT_TYPE_EXPR(...) ::nameof::nameof_short_type() // Obtains type name, with reference and cv-qualifiers, using RTTI. -#define NAMEOF_TYPE_RTTI(...) ::nameof::detail::nameof_type_rtti(typeid(__VA_ARGS__).name()) +#define NAMEOF_TYPE_RTTI(...) ::nameof::detail::nameof_type_rtti<::std::void_t>(typeid(__VA_ARGS__).name()) // Obtains full type name, using RTTI. #define NAMEOF_FULL_TYPE_RTTI(...) ::nameof::detail::nameof_full_type_rtti(typeid(__VA_ARGS__).name())