v0.10.0
This commit is contained in:
Daniil Goncharov 2021-01-12 13:39:52 +05:00 committed by GitHub
parent 6fa49cca4b
commit 7b5d24e37f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 10 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.8) 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) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(IS_TOPLEVEL_PROJECT TRUE) set(IS_TOPLEVEL_PROJECT TRUE)

View file

@ -29,6 +29,18 @@
* To check is nameof_enum supported compiler use macro `NAMEOF_ENUM_SUPPORTED` or constexpr constant `nameof::is_nameof_enum_supported`.</br> * To check is nameof_enum supported compiler use macro `NAMEOF_ENUM_SUPPORTED` or constexpr constant `nameof::is_nameof_enum_supported`.</br>
If nameof_enum used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_ENUM_NO_CHECK_SUPPORT`. 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 <my_lib/string.hpp>
#include <my_lib/string_view.hpp>
#define NAMEOF_USING_ALIAS_STRING using string = my_lib::String;
#define NAMEOF_USING_ALIAS_STRING_VIEW using string_view = my_lib::StringView;
#include <nameof.hpp>
```
## `NAMEOF` ## `NAMEOF`
* Obtains simple (unqualified) name of variable, function, macro. * Obtains simple (unqualified) name of variable, function, macro.

View file

@ -24,8 +24,8 @@
#include <nameof.hpp> #include <nameof.hpp>
enum class Color : int { RED = -10, BLUE = 0, GREEN = 10 }; enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
enum class Numbers : int { One, Two, Three }; enum class Numbers { One, Two, Three };
#if defined(NAMEOF_ENUM_SUPPORTED) #if defined(NAMEOF_ENUM_SUPPORTED)
// Сustom definitions of names for enum. // Сustom definitions of names for enum.

View file

@ -5,7 +5,7 @@
// | |\ | (_| | | | | | | __/ (_) | | | |____|_| |_| // | |\ | (_| | | | | | | __/ (_) | | | |____|_| |_|
// |_| \_|\__,_|_| |_| |_|\___|\___/|_| \_____| // |_| \_|\__,_|_| |_| |_|\___|\___/|_| \_____|
// https://github.com/Neargye/nameof // https://github.com/Neargye/nameof
// version 0.9.5 // version 0.10.0
// //
// Licensed under the MIT License <http://opensource.org/licenses/MIT>. // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
@ -33,8 +33,8 @@
#define NEARGYE_NAMEOF_HPP #define NEARGYE_NAMEOF_HPP
#define NAMEOF_VERSION_MAJOR 0 #define NAMEOF_VERSION_MAJOR 0
#define NAMEOF_VERSION_MINOR 9 #define NAMEOF_VERSION_MINOR 10
#define NAMEOF_VERSION_PATCH 5 #define NAMEOF_VERSION_PATCH 0
#include <array> #include <array>
#include <cassert> #include <cassert>
@ -326,7 +326,7 @@ std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& o
namespace detail { 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] == '\'')) { if (name.size() >= 1 && (name[0] == '"' || name[0] == '\'')) {
return {}; // Narrow multibyte string literal. return {}; // Narrow multibyte string literal.
} else if (name.size() >= 2 && name[0] == 'R' && (name[1] == '"' || name[1] == '\'')) { } 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; break;
} }
} }
if (remove_template_suffix) { if (remove_suffix) {
name.remove_suffix(s); name.remove_suffix(s);
} }
@ -567,9 +567,17 @@ constexpr auto values(std::index_sequence<I...>) noexcept {
template <typename E, bool IsFlags, typename U = std::underlying_type_t<E>> template <typename E, bool IsFlags, typename U = std::underlying_type_t<E>>
constexpr auto values() noexcept { constexpr auto values() noexcept {
static_assert(is_enum_v<E>, "nameof::detail::values requires enum type."); static_assert(is_enum_v<E>, "nameof::detail::values requires enum type.");
constexpr auto range_size = reflected_max_v<E, IsFlags> - reflected_min_v<E, IsFlags> + 1; constexpr auto min = reflected_min_v<E, IsFlags>;
constexpr auto max = reflected_max_v<E, IsFlags>;
constexpr auto range_size = max - min + 1;
static_assert(range_size > 0, "nameof::enum_range requires valid size."); static_assert(range_size > 0, "nameof::enum_range requires valid size.");
static_assert(range_size < (std::numeric_limits<std::uint16_t>::max)(), "nameof::enum_range requires valid size."); static_assert(range_size < (std::numeric_limits<std::uint16_t>::max)(), "nameof::enum_range requires valid size.");
if constexpr (cmp_less((std::numeric_limits<U>::min)(), min) && !IsFlags) {
static_assert(!is_valid<E, value<E, min - 1, IsFlags>(0)>(), "nameof::enum_range detects enum value smaller than min range size.");
}
if constexpr (cmp_less(range_size, (std::numeric_limits<U>::max)()) && !IsFlags) {
static_assert(!is_valid<E, value<E, min, IsFlags>(range_size + 1)>(), "nameof::enum_range detects enum value larger than max range size.");
}
return values<E, IsFlags, reflected_min_v<E, IsFlags>>(std::make_index_sequence<range_size>{}); return values<E, IsFlags, reflected_min_v<E, IsFlags>>(std::make_index_sequence<range_size>{});
} }
@ -987,7 +995,7 @@ template <typename T>
#define NAMEOF_SHORT_TYPE_EXPR(...) ::nameof::nameof_short_type<decltype(__VA_ARGS__)>() #define NAMEOF_SHORT_TYPE_EXPR(...) ::nameof::nameof_short_type<decltype(__VA_ARGS__)>()
// Obtains type name, with reference and cv-qualifiers, using RTTI. // Obtains type name, with reference and cv-qualifiers, using RTTI.
#define NAMEOF_TYPE_RTTI(...) ::nameof::detail::nameof_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name()) #define NAMEOF_TYPE_RTTI(...) ::nameof::detail::nameof_type_rtti<::std::void_t<decltype(__VA_ARGS__)>>(typeid(__VA_ARGS__).name())
// Obtains full type name, using RTTI. // Obtains full type name, using RTTI.
#define NAMEOF_FULL_TYPE_RTTI(...) ::nameof::detail::nameof_full_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name()) #define NAMEOF_FULL_TYPE_RTTI(...) ::nameof::detail::nameof_full_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name())