Skip to content

Commit

Permalink
v0.10.0 (#30)
Browse files Browse the repository at this point in the history
v0.10.0
  • Loading branch information
Neargye authored Jan 12, 2021
1 parent 6fa49cc commit 7b5d24e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 12 additions & 0 deletions doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
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`
* Obtains simple (unqualified) name of variable, function, macro.
Expand Down
4 changes: 2 additions & 2 deletions example/example_custom_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

#include <nameof.hpp>

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.
Expand Down
22 changes: 15 additions & 7 deletions include/nameof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// | |\ | (_| | | | | | | __/ (_) | | | |____|_| |_|
// |_| \_|\__,_|_| |_| |_|\___|\___/|_| \_____|
// https://github.com/Neargye/nameof
// version 0.9.5
// version 0.10.0
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
Expand Down Expand Up @@ -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 <array>
#include <cassert>
Expand Down Expand Up @@ -326,7 +326,7 @@ std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& 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] == '\'')) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -567,9 +567,17 @@ constexpr auto values(std::index_sequence<I...>) noexcept {
template <typename E, bool IsFlags, typename U = std::underlying_type_t<E>>
constexpr auto values() noexcept {
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 < (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>{});
}
Expand Down Expand Up @@ -987,7 +995,7 @@ template <typename T>
#define NAMEOF_SHORT_TYPE_EXPR(...) ::nameof::nameof_short_type<decltype(__VA_ARGS__)>()

// 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.
#define NAMEOF_FULL_TYPE_RTTI(...) ::nameof::detail::nameof_full_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name())
Expand Down

0 comments on commit 7b5d24e

Please sign in to comment.