Skip to content

Commit 7b5d24e

Browse files
authored
v0.10.0 (#30)
v0.10.0
1 parent 6fa49cc commit 7b5d24e

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.8)
22

3-
project(nameof VERSION "0.9.5" LANGUAGES CXX)
3+
project(nameof VERSION "0.10.0" LANGUAGES CXX)
44

55
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
66
set(IS_TOPLEVEL_PROJECT TRUE)

doc/reference.md

+12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
* To check is nameof_enum supported compiler use macro `NAMEOF_ENUM_SUPPORTED` or constexpr constant `nameof::is_nameof_enum_supported`.</br>
3030
If nameof_enum used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_ENUM_NO_CHECK_SUPPORT`.
3131

32+
* To add custom enum or type names see the [example](../example/example_custom_name.cpp).
33+
34+
* To change the type of strings, use special macros:
35+
36+
```cpp
37+
#include <my_lib/string.hpp>
38+
#include <my_lib/string_view.hpp>
39+
#define NAMEOF_USING_ALIAS_STRING using string = my_lib::String;
40+
#define NAMEOF_USING_ALIAS_STRING_VIEW using string_view = my_lib::StringView;
41+
#include <nameof.hpp>
42+
```
43+
3244
## `NAMEOF`
3345
3446
* Obtains simple (unqualified) name of variable, function, macro.

example/example_custom_name.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
#include <nameof.hpp>
2626

27-
enum class Color : int { RED = -10, BLUE = 0, GREEN = 10 };
28-
enum class Numbers : int { One, Two, Three };
27+
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
28+
enum class Numbers { One, Two, Three };
2929

3030
#if defined(NAMEOF_ENUM_SUPPORTED)
3131
// Сustom definitions of names for enum.

include/nameof.hpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// | |\ | (_| | | | | | | __/ (_) | | | |____|_| |_|
66
// |_| \_|\__,_|_| |_| |_|\___|\___/|_| \_____|
77
// https://github.com/Neargye/nameof
8-
// version 0.9.5
8+
// version 0.10.0
99
//
1010
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
1111
// SPDX-License-Identifier: MIT
@@ -33,8 +33,8 @@
3333
#define NEARGYE_NAMEOF_HPP
3434

3535
#define NAMEOF_VERSION_MAJOR 0
36-
#define NAMEOF_VERSION_MINOR 9
37-
#define NAMEOF_VERSION_PATCH 5
36+
#define NAMEOF_VERSION_MINOR 10
37+
#define NAMEOF_VERSION_PATCH 0
3838

3939
#include <array>
4040
#include <cassert>
@@ -326,7 +326,7 @@ std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& o
326326

327327
namespace detail {
328328

329-
constexpr string_view pretty_name(string_view name, bool remove_template_suffix = true) noexcept {
329+
constexpr string_view pretty_name(string_view name, bool remove_suffix = true) noexcept {
330330
if (name.size() >= 1 && (name[0] == '"' || name[0] == '\'')) {
331331
return {}; // Narrow multibyte string literal.
332332
} 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
392392
break;
393393
}
394394
}
395-
if (remove_template_suffix) {
395+
if (remove_suffix) {
396396
name.remove_suffix(s);
397397
}
398398

@@ -567,9 +567,17 @@ constexpr auto values(std::index_sequence<I...>) noexcept {
567567
template <typename E, bool IsFlags, typename U = std::underlying_type_t<E>>
568568
constexpr auto values() noexcept {
569569
static_assert(is_enum_v<E>, "nameof::detail::values requires enum type.");
570-
constexpr auto range_size = reflected_max_v<E, IsFlags> - reflected_min_v<E, IsFlags> + 1;
570+
constexpr auto min = reflected_min_v<E, IsFlags>;
571+
constexpr auto max = reflected_max_v<E, IsFlags>;
572+
constexpr auto range_size = max - min + 1;
571573
static_assert(range_size > 0, "nameof::enum_range requires valid size.");
572574
static_assert(range_size < (std::numeric_limits<std::uint16_t>::max)(), "nameof::enum_range requires valid size.");
575+
if constexpr (cmp_less((std::numeric_limits<U>::min)(), min) && !IsFlags) {
576+
static_assert(!is_valid<E, value<E, min - 1, IsFlags>(0)>(), "nameof::enum_range detects enum value smaller than min range size.");
577+
}
578+
if constexpr (cmp_less(range_size, (std::numeric_limits<U>::max)()) && !IsFlags) {
579+
static_assert(!is_valid<E, value<E, min, IsFlags>(range_size + 1)>(), "nameof::enum_range detects enum value larger than max range size.");
580+
}
573581

574582
return values<E, IsFlags, reflected_min_v<E, IsFlags>>(std::make_index_sequence<range_size>{});
575583
}
@@ -987,7 +995,7 @@ template <typename T>
987995
#define NAMEOF_SHORT_TYPE_EXPR(...) ::nameof::nameof_short_type<decltype(__VA_ARGS__)>()
988996

989997
// Obtains type name, with reference and cv-qualifiers, using RTTI.
990-
#define NAMEOF_TYPE_RTTI(...) ::nameof::detail::nameof_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name())
998+
#define NAMEOF_TYPE_RTTI(...) ::nameof::detail::nameof_type_rtti<::std::void_t<decltype(__VA_ARGS__)>>(typeid(__VA_ARGS__).name())
991999

9921000
// Obtains full type name, using RTTI.
9931001
#define NAMEOF_FULL_TYPE_RTTI(...) ::nameof::detail::nameof_full_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name())

0 commit comments

Comments
 (0)