Add nameof module support
Some checks failed
macos / macos-13 (push) Has been cancelled
macos / macos-14 (push) Has been cancelled
ubuntu / clang-10 (push) Has been cancelled
ubuntu / clang-11 (push) Has been cancelled
ubuntu / clang-12 (push) Has been cancelled
ubuntu / clang-13 (push) Has been cancelled
ubuntu / clang-14 (push) Has been cancelled
ubuntu / clang-15 (push) Has been cancelled
ubuntu / clang-16 (push) Has been cancelled
ubuntu / clang-9 (push) Has been cancelled
ubuntu / gcc-10 (push) Has been cancelled
ubuntu / gcc-11 (push) Has been cancelled
ubuntu / gcc-12 (push) Has been cancelled
ubuntu / gcc-13 (push) Has been cancelled
ubuntu / gcc-14 (push) Has been cancelled
ubuntu / gcc-9 (push) Has been cancelled
windows / Visual Studio 2019 (push) Has been cancelled
windows / Visual Studio 2022 (push) Has been cancelled
Some checks failed
macos / macos-13 (push) Has been cancelled
macos / macos-14 (push) Has been cancelled
ubuntu / clang-10 (push) Has been cancelled
ubuntu / clang-11 (push) Has been cancelled
ubuntu / clang-12 (push) Has been cancelled
ubuntu / clang-13 (push) Has been cancelled
ubuntu / clang-14 (push) Has been cancelled
ubuntu / clang-15 (push) Has been cancelled
ubuntu / clang-16 (push) Has been cancelled
ubuntu / clang-9 (push) Has been cancelled
ubuntu / gcc-10 (push) Has been cancelled
ubuntu / gcc-11 (push) Has been cancelled
ubuntu / gcc-12 (push) Has been cancelled
ubuntu / gcc-13 (push) Has been cancelled
ubuntu / gcc-14 (push) Has been cancelled
ubuntu / gcc-9 (push) Has been cancelled
windows / Visual Studio 2019 (push) Has been cancelled
windows / Visual Studio 2022 (push) Has been cancelled
This commit is contained in:
parent
6c8e87da57
commit
ad4ba073a3
6 changed files with 599 additions and 351 deletions
|
@ -1,4 +1,4 @@
|
||||||
cmake_minimum_required(VERSION 3.14)
|
cmake_minimum_required(VERSION 3.30)
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ endif()
|
||||||
option(NAMEOF_OPT_BUILD_EXAMPLES "Build nameof examples" ${IS_TOPLEVEL_PROJECT})
|
option(NAMEOF_OPT_BUILD_EXAMPLES "Build nameof examples" ${IS_TOPLEVEL_PROJECT})
|
||||||
option(NAMEOF_OPT_BUILD_TESTS "Build and perform nameof tests" ${IS_TOPLEVEL_PROJECT})
|
option(NAMEOF_OPT_BUILD_TESTS "Build and perform nameof tests" ${IS_TOPLEVEL_PROJECT})
|
||||||
option(NAMEOF_OPT_INSTALL "Generate and install nameof target" ${IS_TOPLEVEL_PROJECT})
|
option(NAMEOF_OPT_INSTALL "Generate and install nameof target" ${IS_TOPLEVEL_PROJECT})
|
||||||
|
option(NAMEOF_MODULE "Build nameof module" OFF)
|
||||||
|
|
||||||
if(NAMEOF_OPT_BUILD_EXAMPLES)
|
if(NAMEOF_OPT_BUILD_EXAMPLES)
|
||||||
add_subdirectory(example)
|
add_subdirectory(example)
|
||||||
|
@ -36,14 +37,34 @@ include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
set(EXPORT_NAMESPACE "${PROJECT_NAME}::")
|
set(EXPORT_NAMESPACE "${PROJECT_NAME}::")
|
||||||
|
|
||||||
add_library("${PROJECT_NAME}" INTERFACE)
|
|
||||||
add_library("${EXPORT_NAMESPACE}${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")
|
|
||||||
set(INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
set(INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
|
if(NAMEOF_MODULE)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
add_library(${PROJECT_NAME})
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${INCLUDES}>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE NAMEOF_MODULE)
|
||||||
|
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
|
||||||
|
|
||||||
|
target_sources(${PROJECT_NAME} PUBLIC FILE_SET nameofModules TYPE CXX_MODULES
|
||||||
|
FILES src/nameof.cpp)
|
||||||
|
else()
|
||||||
|
add_library("${PROJECT_NAME}" INTERFACE)
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${PROJECT_NAME}
|
||||||
INTERFACE
|
INTERFACE
|
||||||
$<BUILD_INTERFACE:${INCLUDES}>
|
$<BUILD_INTERFACE:${INCLUDES}>
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library("${EXPORT_NAMESPACE}${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(NAMEOF_OPT_INSTALL)
|
if(NAMEOF_OPT_INSTALL)
|
||||||
list(APPEND CMAKE_MODULE_PATH "${ADDITIONAL_MODULES_DIR}/GenPkgConfig")
|
list(APPEND CMAKE_MODULE_PATH "${ADDITIONAL_MODULES_DIR}/GenPkgConfig")
|
||||||
|
@ -54,6 +75,10 @@ if(NAMEOF_OPT_INSTALL)
|
||||||
string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}")
|
string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}")
|
||||||
install(TARGETS "${PROJECT_NAME}"
|
install(TARGETS "${PROJECT_NAME}"
|
||||||
EXPORT ${PROJECT_NAME}
|
EXPORT ${PROJECT_NAME}
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
FILE_SET nameofModules DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
INCLUDES
|
INCLUDES
|
||||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||||
# COMPONENT "${SDK_COMPONENT_NAME}" # component is not allowed for includes! Headers are installed separately! Includes only marks the headers for export
|
# COMPONENT "${SDK_COMPONENT_NAME}" # component is not allowed for includes! Headers are installed separately! Includes only marks the headers for export
|
||||||
|
|
|
@ -12,10 +12,12 @@ endif()
|
||||||
function(make_example target)
|
function(make_example target)
|
||||||
add_executable(${target} ${target}.cpp)
|
add_executable(${target} ${target}.cpp)
|
||||||
set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF)
|
set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF)
|
||||||
target_compile_features(${target} PRIVATE cxx_std_17)
|
|
||||||
target_compile_options(${target} PRIVATE ${OPTIONS})
|
target_compile_options(${target} PRIVATE ${OPTIONS})
|
||||||
target_link_libraries(${target} PRIVATE ${CMAKE_PROJECT_NAME})
|
target_link_libraries(${target} PRIVATE ${CMAKE_PROJECT_NAME})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
make_example(example)
|
make_example(example)
|
||||||
make_example(example_custom_name)
|
make_example(example_custom_name)
|
||||||
|
if(NAMEOF_MODULE)
|
||||||
|
make_example(example_module)
|
||||||
|
endif()
|
||||||
|
|
11
example/example_module.cpp
Normal file
11
example/example_module.cpp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import nameof;
|
||||||
|
#include <nameof_macro.hpp>
|
||||||
|
|
||||||
|
struct Test {};
|
||||||
|
|
||||||
|
auto main() -> int {
|
||||||
|
auto _ = nameof::nameof_type<Test>();
|
||||||
|
{
|
||||||
|
auto _ = NAMEOF_TYPE(Test);
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,14 +32,27 @@
|
||||||
#ifndef NEARGYE_NAMEOF_HPP
|
#ifndef NEARGYE_NAMEOF_HPP
|
||||||
#define NEARGYE_NAMEOF_HPP
|
#define NEARGYE_NAMEOF_HPP
|
||||||
|
|
||||||
#define NAMEOF_VERSION_MAJOR 0
|
#include "nameof_macro.hpp"
|
||||||
#define NAMEOF_VERSION_MINOR 10
|
|
||||||
#define NAMEOF_VERSION_PATCH 4
|
#ifdef NAMEOF_MODULE
|
||||||
|
|
||||||
|
#define NAMEOF_EXPORT export
|
||||||
|
|
||||||
|
#define NAMEOF_EXPORT_BEGIN export {
|
||||||
|
#define NAMEOF_EXPORT_END }
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define NAMEOF_EXPORT
|
||||||
|
#define NAMEOF_EXPORT_BEGIN
|
||||||
|
#define NAMEOF_EXPORT_END
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
@ -55,6 +68,7 @@
|
||||||
|
|
||||||
#if __has_include(<cxxabi.h>)
|
#if __has_include(<cxxabi.h>)
|
||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -68,73 +82,16 @@
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 26495) // Variable 'cstring<N>::chars_' is uninitialized.
|
#pragma warning(disable : 26495) // Variable 'cstring<N>::chars_' is uninitialized.
|
||||||
# pragma warning(disable : 28020) // Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value.
|
#pragma warning( \
|
||||||
|
disable : 28020) // Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value.
|
||||||
#pragma warning(disable : 26451) // The expression '0<=_Param_(1)&&_Param_(1)<=1-1' is not true at this call.
|
#pragma warning(disable : 26451) // The expression '0<=_Param_(1)&&_Param_(1)<=1-1' is not true at this call.
|
||||||
#pragma warning(disable : 4514) // Unreferenced inline function has been removed.
|
#pragma warning(disable : 4514) // Unreferenced inline function has been removed.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Checks nameof_type compiler compatibility.
|
|
||||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || defined(_MSC_VER) && _MSC_VER >= 1910
|
|
||||||
# undef NAMEOF_TYPE_SUPPORTED
|
|
||||||
# define NAMEOF_TYPE_SUPPORTED 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Checks nameof_type_rtti compiler compatibility.
|
|
||||||
#if defined(__clang__)
|
|
||||||
# if __has_feature(cxx_rtti)
|
|
||||||
# undef NAMEOF_TYPE_RTTI_SUPPORTED
|
|
||||||
# define NAMEOF_TYPE_RTTI_SUPPORTED 1
|
|
||||||
# endif
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
# if defined(__GXX_RTTI)
|
|
||||||
# undef NAMEOF_TYPE_RTTI_SUPPORTED
|
|
||||||
# define NAMEOF_TYPE_RTTI_SUPPORTED 1
|
|
||||||
# endif
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
# if defined(_CPPRTTI)
|
|
||||||
# undef NAMEOF_TYPE_RTTI_SUPPORTED
|
|
||||||
# define NAMEOF_TYPE_RTTI_SUPPORTED 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Checks nameof_member compiler compatibility.
|
|
||||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 202002L
|
|
||||||
# undef NAMEOF_MEMBER_SUPPORTED
|
|
||||||
# define NAMEOF_MEMBER_SUPPORTED 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Checks nameof_pointer compiler compatibility.
|
|
||||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 202002L
|
|
||||||
# undef NAMEOF_POINTER_SUPPORTED
|
|
||||||
# define NAMEOF_POINTER_SUPPORTED 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Checks nameof_enum compiler compatibility.
|
|
||||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER) && _MSC_VER >= 1910
|
|
||||||
# undef NAMEOF_ENUM_SUPPORTED
|
|
||||||
# define NAMEOF_ENUM_SUPPORTED 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Checks nameof_enum compiler aliases compatibility.
|
|
||||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER) && _MSC_VER >= 1920
|
|
||||||
# undef NAMEOF_ENUM_SUPPORTED_ALIASES
|
|
||||||
# define NAMEOF_ENUM_SUPPORTED_ALIASES 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enum value must be greater or equals than NAMEOF_ENUM_RANGE_MIN. By default NAMEOF_ENUM_RANGE_MIN = -128.
|
|
||||||
// If need another min range for all enum types by default, redefine the macro NAMEOF_ENUM_RANGE_MIN.
|
|
||||||
#if !defined(NAMEOF_ENUM_RANGE_MIN)
|
|
||||||
# define NAMEOF_ENUM_RANGE_MIN -128
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enum value must be less or equals than NAMEOF_ENUM_RANGE_MAX. By default NAMEOF_ENUM_RANGE_MAX = 128.
|
|
||||||
// If need another max range for all enum types by default, redefine the macro NAMEOF_ENUM_RANGE_MAX.
|
|
||||||
#if !defined(NAMEOF_ENUM_RANGE_MAX)
|
|
||||||
# define NAMEOF_ENUM_RANGE_MAX 128
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace nameof {
|
namespace nameof {
|
||||||
|
|
||||||
|
NAMEOF_EXPORT_BEGIN
|
||||||
|
|
||||||
// If need another string_view type, define the macro NAMEOF_USING_ALIAS_STRING_VIEW.
|
// If need another string_view type, define the macro NAMEOF_USING_ALIAS_STRING_VIEW.
|
||||||
#if defined(NAMEOF_USING_ALIAS_STRING_VIEW)
|
#if defined(NAMEOF_USING_ALIAS_STRING_VIEW)
|
||||||
NAMEOF_USING_ALIAS_STRING_VIEW
|
NAMEOF_USING_ALIAS_STRING_VIEW
|
||||||
|
@ -151,9 +108,9 @@ using std::string;
|
||||||
|
|
||||||
namespace customize {
|
namespace customize {
|
||||||
|
|
||||||
// Enum value must be in range [NAMEOF_ENUM_RANGE_MIN, NAMEOF_ENUM_RANGE_MAX]. By default NAMEOF_ENUM_RANGE_MIN = -128, NAMEOF_ENUM_RANGE_MAX = 128.
|
// Enum value must be in range [NAMEOF_ENUM_RANGE_MIN, NAMEOF_ENUM_RANGE_MAX]. By default NAMEOF_ENUM_RANGE_MIN = -128,
|
||||||
// If you need another range for all enum types by default, redefine the macro NAMEOF_ENUM_RANGE_MIN and NAMEOF_ENUM_RANGE_MAX.
|
// NAMEOF_ENUM_RANGE_MAX = 128. If you need another range for all enum types by default, redefine the macro NAMEOF_ENUM_RANGE_MIN and
|
||||||
// If you need another range for specific enum type, add specialization enum_range for necessary enum type.
|
// NAMEOF_ENUM_RANGE_MAX. If you need another range for specific enum type, add specialization enum_range for necessary enum type.
|
||||||
template <typename E>
|
template <typename E>
|
||||||
struct enum_range {
|
struct enum_range {
|
||||||
static_assert(std::is_enum_v<E>, "nameof::customize::enum_range requires enum type.");
|
static_assert(std::is_enum_v<E>, "nameof::customize::enum_range requires enum type.");
|
||||||
|
@ -195,7 +152,7 @@ constexpr string_view pointer_name() noexcept {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace nameof::customize
|
} // namespace customize
|
||||||
|
|
||||||
template <std::uint16_t N>
|
template <std::uint16_t N>
|
||||||
class [[nodiscard]] cstring {
|
class [[nodiscard]] cstring {
|
||||||
|
@ -230,51 +187,94 @@ class [[nodiscard]] cstring {
|
||||||
|
|
||||||
cstring& operator=(cstring&&) = default;
|
cstring& operator=(cstring&&) = default;
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_pointer data() const noexcept { return chars_; }
|
[[nodiscard]] constexpr const_pointer data() const noexcept {
|
||||||
|
return chars_;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr size_type size() const noexcept { return N; }
|
[[nodiscard]] constexpr size_type size() const noexcept {
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_iterator begin() const noexcept { return data(); }
|
[[nodiscard]] constexpr const_iterator begin() const noexcept {
|
||||||
|
return data();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_iterator end() const noexcept { return data() + size(); }
|
[[nodiscard]] constexpr const_iterator end() const noexcept {
|
||||||
|
return data() + size();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_iterator cbegin() const noexcept { return begin(); }
|
[[nodiscard]] constexpr const_iterator cbegin() const noexcept {
|
||||||
|
return begin();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_iterator cend() const noexcept { return end(); }
|
[[nodiscard]] constexpr const_iterator cend() const noexcept {
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept { return end(); }
|
[[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept {
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reverse_iterator rend() const noexcept { return begin(); }
|
[[nodiscard]] constexpr const_reverse_iterator rend() const noexcept {
|
||||||
|
return begin();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reverse_iterator crbegin() const noexcept { return rbegin(); }
|
[[nodiscard]] constexpr const_reverse_iterator crbegin() const noexcept {
|
||||||
|
return rbegin();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reverse_iterator crend() const noexcept { return rend(); }
|
[[nodiscard]] constexpr const_reverse_iterator crend() const noexcept {
|
||||||
|
return rend();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reference operator[](size_type i) const noexcept { return assert(i < size()), chars_[i]; }
|
[[nodiscard]] constexpr const_reference operator[](size_type i) const noexcept {
|
||||||
|
return assert(i < size()), chars_[i];
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reference front() const noexcept { return chars_[0]; }
|
[[nodiscard]] constexpr const_reference front() const noexcept {
|
||||||
|
return chars_[0];
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reference back() const noexcept { return chars_[N]; }
|
[[nodiscard]] constexpr const_reference back() const noexcept {
|
||||||
|
return chars_[N];
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr size_type length() const noexcept { return size(); }
|
[[nodiscard]] constexpr size_type length() const noexcept {
|
||||||
|
return size();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr bool empty() const noexcept { return false; }
|
[[nodiscard]] constexpr bool empty() const noexcept {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr int compare(string_view str) const noexcept { return string_view{data(), size()}.compare(str); }
|
[[nodiscard]] constexpr int compare(string_view str) const noexcept {
|
||||||
|
return string_view{data(), size()}.compare(str);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const char* c_str() const noexcept { return data(); }
|
[[nodiscard]] constexpr const char* c_str() const noexcept {
|
||||||
|
return data();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] string str() const { return {begin(), end()}; }
|
[[nodiscard]] string str() const {
|
||||||
|
return {begin(), end()};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr operator string_view() const noexcept { return {data(), size()}; }
|
[[nodiscard]] constexpr operator string_view() const noexcept {
|
||||||
|
return {data(), size()};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr explicit operator const_pointer() const noexcept { return data(); }
|
[[nodiscard]] constexpr explicit operator const_pointer() const noexcept {
|
||||||
|
return data();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] explicit operator string() const { return {begin(), end()}; }
|
[[nodiscard]] explicit operator string() const {
|
||||||
|
return {begin(), end()};
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <std::uint16_t... I>
|
template <std::uint16_t... I>
|
||||||
constexpr cstring(string_view str, std::integer_sequence<std::uint16_t, I...>) noexcept : chars_{str[I]..., '\0'} {}
|
constexpr cstring(string_view str, std::integer_sequence<std::uint16_t, I...>) noexcept : chars_{str[I]..., '\0'} {
|
||||||
|
}
|
||||||
|
|
||||||
char chars_[static_cast<std::size_t>(N) + 1];
|
char chars_[static_cast<std::size_t>(N) + 1];
|
||||||
};
|
};
|
||||||
|
@ -296,7 +296,8 @@ class [[nodiscard]] cstring<0> {
|
||||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||||
|
|
||||||
constexpr explicit cstring(string_view) noexcept {}
|
constexpr explicit cstring(string_view) noexcept {
|
||||||
|
}
|
||||||
|
|
||||||
constexpr cstring() = default;
|
constexpr cstring() = default;
|
||||||
|
|
||||||
|
@ -310,41 +311,77 @@ class [[nodiscard]] cstring<0> {
|
||||||
|
|
||||||
cstring& operator=(cstring&&) = default;
|
cstring& operator=(cstring&&) = default;
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_pointer data() const noexcept { return nullptr; }
|
[[nodiscard]] constexpr const_pointer data() const noexcept {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr size_type size() const noexcept { return 0; }
|
[[nodiscard]] constexpr size_type size() const noexcept {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_iterator begin() const noexcept { return nullptr; }
|
[[nodiscard]] constexpr const_iterator begin() const noexcept {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_iterator end() const noexcept { return nullptr; }
|
[[nodiscard]] constexpr const_iterator end() const noexcept {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_iterator cbegin() const noexcept { return nullptr; }
|
[[nodiscard]] constexpr const_iterator cbegin() const noexcept {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_iterator cend() const noexcept { return nullptr; }
|
[[nodiscard]] constexpr const_iterator cend() const noexcept {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept { return {}; }
|
[[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reverse_iterator rend() const noexcept { return {}; }
|
[[nodiscard]] constexpr const_reverse_iterator rend() const noexcept {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reverse_iterator crbegin() const noexcept { return {}; }
|
[[nodiscard]] constexpr const_reverse_iterator crbegin() const noexcept {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const_reverse_iterator crend() const noexcept { return {}; }
|
[[nodiscard]] constexpr const_reverse_iterator crend() const noexcept {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr size_type length() const noexcept { return 0; }
|
[[nodiscard]] constexpr size_type length() const noexcept {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr bool empty() const noexcept { return true; }
|
[[nodiscard]] constexpr bool empty() const noexcept {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr int compare(string_view str) const noexcept { return string_view{}.compare(str); }
|
[[nodiscard]] constexpr int compare(string_view str) const noexcept {
|
||||||
|
return string_view{}.compare(str);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const char* c_str() const noexcept { return nullptr; }
|
[[nodiscard]] constexpr const char* c_str() const noexcept {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] string str() const { return {}; }
|
[[nodiscard]] string str() const {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr operator string_view() const noexcept { return {}; }
|
[[nodiscard]] constexpr operator string_view() const noexcept {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr explicit operator const_pointer() const noexcept { return nullptr; }
|
[[nodiscard]] constexpr explicit operator const_pointer() const noexcept {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] explicit operator string() const { return {}; }
|
[[nodiscard]] explicit operator string() const {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <std::uint16_t N>
|
template <std::uint16_t N>
|
||||||
|
@ -415,6 +452,8 @@ std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& o
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMEOF_EXPORT_END
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
constexpr string_view pretty_name(string_view name, bool remove_suffix = true) noexcept {
|
constexpr string_view pretty_name(string_view name, bool remove_suffix = true) noexcept {
|
||||||
|
@ -475,10 +514,8 @@ constexpr string_view pretty_name(string_view name, bool remove_suffix = true) n
|
||||||
}
|
}
|
||||||
|
|
||||||
for(std::size_t i = name.size() - s; i > 0; --i) {
|
for(std::size_t i = name.size() - s; i > 0; --i) {
|
||||||
if (!((name[i - 1] >= '0' && name[i - 1] <= '9') ||
|
if(!((name[i - 1] >= '0' && name[i - 1] <= '9') || (name[i - 1] >= 'a' && name[i - 1] <= 'z') ||
|
||||||
(name[i - 1] >= 'a' && name[i - 1] <= 'z') ||
|
(name[i - 1] >= 'A' && name[i - 1] <= 'Z') || (name[i - 1] == '_'))) {
|
||||||
(name[i - 1] >= 'A' && name[i - 1] <= 'Z') ||
|
|
||||||
(name[i - 1] == '_'))) {
|
|
||||||
name.remove_prefix(i);
|
name.remove_prefix(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -487,9 +524,7 @@ constexpr string_view pretty_name(string_view name, bool remove_suffix = true) n
|
||||||
name.remove_suffix(s);
|
name.remove_suffix(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.size() > 0 && ((name[0] >= 'a' && name[0] <= 'z') ||
|
if(name.size() > 0 && ((name[0] >= 'a' && name[0] <= 'z') || (name[0] >= 'A' && name[0] <= 'Z') || (name[0] == '_'))) {
|
||||||
(name[0] >= 'A' && name[0] <= 'Z') ||
|
|
||||||
(name[0] == '_'))) {
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,7 +568,8 @@ constexpr I log2(I value) noexcept {
|
||||||
return assert(false), value;
|
return assert(false), value;
|
||||||
} else {
|
} else {
|
||||||
auto ret = I{0};
|
auto ret = I{0};
|
||||||
for (; value > I{1}; value >>= I{1}, ++ret) {}
|
for(; value > I{1}; value >>= I{1}, ++ret) {
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -542,9 +578,11 @@ constexpr I log2(I value) noexcept {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct nameof_enum_supported
|
struct nameof_enum_supported
|
||||||
#if defined(NAMEOF_ENUM_SUPPORTED) && NAMEOF_ENUM_SUPPORTED || defined(NAMEOF_ENUM_NO_CHECK_SUPPORT)
|
#if defined(NAMEOF_ENUM_SUPPORTED) && NAMEOF_ENUM_SUPPORTED || defined(NAMEOF_ENUM_NO_CHECK_SUPPORT)
|
||||||
: std::true_type {};
|
: std::true_type {
|
||||||
|
};
|
||||||
#else
|
#else
|
||||||
: std::false_type {};
|
: std::false_type {
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename T, typename R>
|
template <typename T, typename R>
|
||||||
|
@ -653,14 +691,35 @@ constexpr int reflected_max() noexcept {
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NAMEOF_FOR_EACH_256(T) \
|
#define NAMEOF_FOR_EACH_256(T) \
|
||||||
T( 0)T( 1)T( 2)T( 3)T( 4)T( 5)T( 6)T( 7)T( 8)T( 9)T( 10)T( 11)T( 12)T( 13)T( 14)T( 15)T( 16)T( 17)T( 18)T( 19)T( 20)T( 21)T( 22)T( 23)T( 24)T( 25)T( 26)T( 27)T( 28)T( 29)T( 30)T( 31) \
|
T(0) \
|
||||||
T( 32)T( 33)T( 34)T( 35)T( 36)T( 37)T( 38)T( 39)T( 40)T( 41)T( 42)T( 43)T( 44)T( 45)T( 46)T( 47)T( 48)T( 49)T( 50)T( 51)T( 52)T( 53)T( 54)T( 55)T( 56)T( 57)T( 58)T( 59)T( 60)T( 61)T( 62)T( 63) \
|
T(1) \
|
||||||
T( 64)T( 65)T( 66)T( 67)T( 68)T( 69)T( 70)T( 71)T( 72)T( 73)T( 74)T( 75)T( 76)T( 77)T( 78)T( 79)T( 80)T( 81)T( 82)T( 83)T( 84)T( 85)T( 86)T( 87)T( 88)T( 89)T( 90)T( 91)T( 92)T( 93)T( 94)T( 95) \
|
T(2) \
|
||||||
T( 96)T( 97)T( 98)T( 99)T(100)T(101)T(102)T(103)T(104)T(105)T(106)T(107)T(108)T(109)T(110)T(111)T(112)T(113)T(114)T(115)T(116)T(117)T(118)T(119)T(120)T(121)T(122)T(123)T(124)T(125)T(126)T(127) \
|
T(3) \
|
||||||
T(128)T(129)T(130)T(131)T(132)T(133)T(134)T(135)T(136)T(137)T(138)T(139)T(140)T(141)T(142)T(143)T(144)T(145)T(146)T(147)T(148)T(149)T(150)T(151)T(152)T(153)T(154)T(155)T(156)T(157)T(158)T(159) \
|
T(4) \
|
||||||
T(160)T(161)T(162)T(163)T(164)T(165)T(166)T(167)T(168)T(169)T(170)T(171)T(172)T(173)T(174)T(175)T(176)T(177)T(178)T(179)T(180)T(181)T(182)T(183)T(184)T(185)T(186)T(187)T(188)T(189)T(190)T(191) \
|
T(5) \
|
||||||
T(192)T(193)T(194)T(195)T(196)T(197)T(198)T(199)T(200)T(201)T(202)T(203)T(204)T(205)T(206)T(207)T(208)T(209)T(210)T(211)T(212)T(213)T(214)T(215)T(216)T(217)T(218)T(219)T(220)T(221)T(222)T(223) \
|
T(6) \
|
||||||
T(224)T(225)T(226)T(227)T(228)T(229)T(230)T(231)T(232)T(233)T(234)T(235)T(236)T(237)T(238)T(239)T(240)T(241)T(242)T(243)T(244)T(245)T(246)T(247)T(248)T(249)T(250)T(251)T(252)T(253)T(254)T(255)
|
T(7) \
|
||||||
|
T(8) \
|
||||||
|
T(9) \
|
||||||
|
T(10) \
|
||||||
|
T(11) \
|
||||||
|
T(12) \
|
||||||
|
T(13) T(14) T(15) T(16) T(17) T(18) T(19) T(20) T(21) T(22) T(23) T(24) T(25) T(26) T(27) T(28) T(29) T(30) T(31) T(32) T(33) T(34) \
|
||||||
|
T(35) T(36) T(37) T(38) T(39) T(40) T(41) T(42) T(43) T(44) T(45) T(46) T(47) T(48) T(49) T(50) T(51) T(52) T(53) T(54) T(55) T(56) \
|
||||||
|
T(57) T(58) T(59) T(60) T(61) T(62) T(63) T(64) T(65) T(66) T(67) T(68) T(69) T(70) T(71) T(72) T(73) T(74) T(75) T(76) T(77) \
|
||||||
|
T(78) T(79) T(80) T(81) T(82) T(83) T(84) T(85) T(86) T(87) T(88) T(89) T(90) T(91) T(92) T(93) T(94) T(95) T(96) T(97) \
|
||||||
|
T(98) T(99) T(100) T(101) T(102) T(103) T(104) T(105) T(106) T(107) T(108) T(109) T(110) T(111) T(112) T(113) T(114) \
|
||||||
|
T(115) T(116) T(117) T(118) T(119) T(120) T(121) T(122) T(123) T(124) T(125) T(126) T(127) T(128) T(129) T(130) \
|
||||||
|
T(131) T(132) T(133) T(134) T(135) T(136) T(137) T(138) T(139) T(140) T(141) T(142) T(143) T(144) T(145) T(146) \
|
||||||
|
T(147) T(148) T(149) T(150) T(151) T(152) T(153) T(154) T(155) T(156) T(157) T(158) T(159) T(160) T(161) \
|
||||||
|
T(162) T(163) T(164) T(165) T(166) T(167) T(168) T(169) T(170) T(171) T(172) T(173) T(174) T(175) T(176) \
|
||||||
|
T(177) T(178) T(179) T(180) T(181) T(182) T(183) T(184) T(185) T(186) T(187) T(188) T(189) T(190) \
|
||||||
|
T(191) T(192) T(193) T(194) T(195) T(196) T(197) T(198) T(199) T(200) T(201) T(202) T(203) \
|
||||||
|
T(204) T(205) T(206) T(207) T(208) T(209) T(210) T(211) T(212) T(213) T(214) T(215) T(216) \
|
||||||
|
T(217) T(218) T(219) T(220) T(221) T(222) T(223) T(224) T(225) T(226) T(227) T(228) \
|
||||||
|
T(229) T(230) T(231) T(232) T(233) T(234) T(235) T(236) T(237) T(238) T(239) T(240) \
|
||||||
|
T(241) T(242) T(243) T(244) T(245) T(246) T(247) T(248) T(249) T(250) T(251) \
|
||||||
|
T(252) T(253) T(254) T(255)
|
||||||
|
|
||||||
template <typename E, bool IsFlags, std::size_t Size, int Min, std::size_t I>
|
template <typename E, bool IsFlags, std::size_t Size, int Min, std::size_t I>
|
||||||
constexpr void valid_count(bool* valid, std::size_t& count) noexcept {
|
constexpr void valid_count(bool* valid, std::size_t& count) noexcept {
|
||||||
|
@ -782,33 +841,41 @@ constexpr E enum_value(std::size_t i) noexcept {
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
struct nameof_type_supported
|
struct nameof_type_supported
|
||||||
#if defined(NAMEOF_TYPE_SUPPORTED) && NAMEOF_TYPE_SUPPORTED || defined(NAMEOF_TYPE_NO_CHECK_SUPPORT)
|
#if defined(NAMEOF_TYPE_SUPPORTED) && NAMEOF_TYPE_SUPPORTED || defined(NAMEOF_TYPE_NO_CHECK_SUPPORT)
|
||||||
: std::true_type {};
|
: std::true_type {
|
||||||
|
};
|
||||||
#else
|
#else
|
||||||
: std::false_type {};
|
: std::false_type {
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
struct nameof_type_rtti_supported
|
struct nameof_type_rtti_supported
|
||||||
#if defined(NAMEOF_TYPE_RTTI_SUPPORTED) && NAMEOF_TYPE_RTTI_SUPPORTED || defined(NAMEOF_TYPE_NO_CHECK_SUPPORT)
|
#if defined(NAMEOF_TYPE_RTTI_SUPPORTED) && NAMEOF_TYPE_RTTI_SUPPORTED || defined(NAMEOF_TYPE_NO_CHECK_SUPPORT)
|
||||||
: std::true_type {};
|
: std::true_type {
|
||||||
|
};
|
||||||
#else
|
#else
|
||||||
: std::false_type {};
|
: std::false_type {
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
struct nameof_member_supported
|
struct nameof_member_supported
|
||||||
#if defined(NAMEOF_MEMBER_SUPPORTED) && NAMEOF_MEMBER_SUPPORTED || defined(NAMEOF_TYPE_NO_CHECK_SUPPORT)
|
#if defined(NAMEOF_MEMBER_SUPPORTED) && NAMEOF_MEMBER_SUPPORTED || defined(NAMEOF_TYPE_NO_CHECK_SUPPORT)
|
||||||
: std::true_type {};
|
: std::true_type {
|
||||||
|
};
|
||||||
#else
|
#else
|
||||||
: std::false_type {};
|
: std::false_type {
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
struct nameof_pointer_supported
|
struct nameof_pointer_supported
|
||||||
#if defined(NAMEOF_POINTER_SUPPORTED) && NAMEOF_POINTER_SUPPORTED || defined(NAMEOF_TYPE_NO_CHECK_SUPPORT)
|
#if defined(NAMEOF_POINTER_SUPPORTED) && NAMEOF_POINTER_SUPPORTED || defined(NAMEOF_TYPE_NO_CHECK_SUPPORT)
|
||||||
: std::true_type {};
|
: std::true_type {
|
||||||
|
};
|
||||||
#else
|
#else
|
||||||
: std::false_type {};
|
: std::false_type {
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER) && !defined(__clang__)
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
@ -857,7 +924,8 @@ inline constexpr auto type_name_v = n<T...>();
|
||||||
#if __has_include(<cxxabi.h>)
|
#if __has_include(<cxxabi.h>)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
string nameof_type_rtti(const char* tn) {
|
string nameof_type_rtti(const char* tn) {
|
||||||
static_assert(nameof_type_rtti_supported<T>::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(nameof_type_rtti_supported<T>::value,
|
||||||
|
"nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
|
const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
|
||||||
const auto name = string{dmg};
|
const auto name = string{dmg};
|
||||||
free(dmg);
|
free(dmg);
|
||||||
|
@ -868,7 +936,8 @@ string nameof_type_rtti(const char* tn) {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
string nameof_full_type_rtti(const char* tn) {
|
string nameof_full_type_rtti(const char* tn) {
|
||||||
static_assert(nameof_type_rtti_supported<T>::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(nameof_type_rtti_supported<T>::value,
|
||||||
|
"nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
|
const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
|
||||||
auto name = string{dmg};
|
auto name = string{dmg};
|
||||||
free(dmg);
|
free(dmg);
|
||||||
|
@ -891,7 +960,8 @@ string nameof_full_type_rtti(const char* tn) {
|
||||||
|
|
||||||
template <typename T, enable_if_has_short_name_t<T, int> = 0>
|
template <typename T, enable_if_has_short_name_t<T, int> = 0>
|
||||||
string nameof_short_type_rtti(const char* tn) {
|
string nameof_short_type_rtti(const char* tn) {
|
||||||
static_assert(nameof_type_rtti_supported<T>::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(nameof_type_rtti_supported<T>::value,
|
||||||
|
"nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
|
const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
|
||||||
const auto pname = pretty_name(dmg);
|
const auto pname = pretty_name(dmg);
|
||||||
const auto name = string{pname.data(), pname.size()};
|
const auto name = string{pname.data(), pname.size()};
|
||||||
|
@ -903,7 +973,8 @@ string nameof_short_type_rtti(const char* tn) {
|
||||||
#else
|
#else
|
||||||
template <typename T>
|
template <typename T>
|
||||||
string nameof_type_rtti(const char* tn) {
|
string nameof_type_rtti(const char* tn) {
|
||||||
static_assert(nameof_type_rtti_supported<T>::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(nameof_type_rtti_supported<T>::value,
|
||||||
|
"nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
const auto name = string_view{tn};
|
const auto name = string_view{tn};
|
||||||
assert(!name.empty() && "Type does not have a name.");
|
assert(!name.empty() && "Type does not have a name.");
|
||||||
return {name.data(), name.size()};
|
return {name.data(), name.size()};
|
||||||
|
@ -911,7 +982,8 @@ string nameof_type_rtti(const char* tn) {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
string nameof_full_type_rtti(const char* tn) {
|
string nameof_full_type_rtti(const char* tn) {
|
||||||
static_assert(nameof_type_rtti_supported<T>::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(nameof_type_rtti_supported<T>::value,
|
||||||
|
"nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
auto name = string{tn};
|
auto name = string{tn};
|
||||||
assert(!name.empty() && "Type does not have a name.");
|
assert(!name.empty() && "Type does not have a name.");
|
||||||
if constexpr(std::is_const_v<std::remove_reference_t<T>>) {
|
if constexpr(std::is_const_v<std::remove_reference_t<T>>) {
|
||||||
|
@ -931,7 +1003,8 @@ string nameof_full_type_rtti(const char* tn) {
|
||||||
|
|
||||||
template <typename T, enable_if_has_short_name_t<T, int> = 0>
|
template <typename T, enable_if_has_short_name_t<T, int> = 0>
|
||||||
string nameof_short_type_rtti(const char* tn) {
|
string nameof_short_type_rtti(const char* tn) {
|
||||||
static_assert(nameof_type_rtti_supported<T>::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(nameof_type_rtti_supported<T>::value,
|
||||||
|
"nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
const auto name = pretty_name(tn);
|
const auto name = pretty_name(tn);
|
||||||
assert(!name.empty() && "Type does not have a short name.");
|
assert(!name.empty() && "Type does not have a short name.");
|
||||||
return {name.data(), name.size()};
|
return {name.data(), name.size()};
|
||||||
|
@ -946,8 +1019,7 @@ constexpr auto n() noexcept {
|
||||||
#if defined(__clang__) || defined(__GNUC__)
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
constexpr auto name = pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2});
|
constexpr auto name = pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2});
|
||||||
#elif defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 202002L
|
#elif defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 202002L
|
||||||
constexpr auto name = pretty_name({__FUNCSIG__,
|
constexpr auto name = pretty_name({__FUNCSIG__, sizeof(__FUNCSIG__) - 18 + std::is_member_function_pointer_v<decltype(U)>});
|
||||||
sizeof(__FUNCSIG__) - 18 + std::is_member_function_pointer_v<decltype(U)>});
|
|
||||||
#else
|
#else
|
||||||
constexpr auto name = string_view{};
|
constexpr auto name = string_view{};
|
||||||
#endif
|
#endif
|
||||||
|
@ -981,7 +1053,9 @@ consteval auto get_member_name() noexcept {
|
||||||
return n<V>();
|
return n<V>();
|
||||||
} else {
|
} else {
|
||||||
constexpr bool is_defined = sizeof(decltype(get_base_type(V))) != 0;
|
constexpr bool is_defined = sizeof(decltype(get_base_type(V))) != 0;
|
||||||
static_assert(is_defined, "nameof::nameof_member member name can use only if the struct is already fully defined. Please use NAMEOF macro, or separate definition and declaration.");
|
static_assert(is_defined,
|
||||||
|
"nameof::nameof_member member name can use only if the struct is already fully defined. Please use NAMEOF macro, or "
|
||||||
|
"separate definition and declaration.");
|
||||||
if constexpr(is_defined) {
|
if constexpr(is_defined) {
|
||||||
return n<V, Store{&(nonexist_object<decltype(get_base_type(V))>.*V)}>();
|
return n<V, Store{&(nonexist_object<decltype(get_base_type(V))>.*V)}>();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1008,7 +1082,8 @@ constexpr bool is_nullptr_v = is_same<P, static_cast<std::remove_reference_t<dec
|
||||||
|
|
||||||
template <auto V>
|
template <auto V>
|
||||||
constexpr auto p() noexcept {
|
constexpr auto p() noexcept {
|
||||||
[[maybe_unused]] constexpr auto custom_name = customize::pointer_name<V>().empty() && is_nullptr_v<V> ? "nullptr" : customize::pointer_name<V>();
|
[[maybe_unused]] constexpr auto custom_name =
|
||||||
|
customize::pointer_name<V>().empty() && is_nullptr_v<V> ? "nullptr" : customize::pointer_name<V>();
|
||||||
|
|
||||||
if constexpr(custom_name.empty() && nameof_pointer_supported<decltype(V)>::value) {
|
if constexpr(custom_name.empty() && nameof_pointer_supported<decltype(V)>::value) {
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
|
@ -1030,7 +1105,9 @@ constexpr auto p() noexcept {
|
||||||
template <auto V>
|
template <auto V>
|
||||||
inline constexpr auto pointer_name_v = p<V>();
|
inline constexpr auto pointer_name_v = p<V>();
|
||||||
|
|
||||||
} // namespace nameof::detail
|
} // namespace detail
|
||||||
|
|
||||||
|
NAMEOF_EXPORT_BEGIN
|
||||||
|
|
||||||
// Checks is nameof_type supported compiler.
|
// Checks is nameof_type supported compiler.
|
||||||
inline constexpr bool is_nameof_type_supported = detail::nameof_type_supported<void>::value;
|
inline constexpr bool is_nameof_type_supported = detail::nameof_type_supported<void>::value;
|
||||||
|
@ -1052,7 +1129,8 @@ template <typename E>
|
||||||
[[nodiscard]] constexpr auto nameof_enum(E value) noexcept -> detail::enable_if_enum_t<E, string_view> {
|
[[nodiscard]] constexpr auto nameof_enum(E value) noexcept -> detail::enable_if_enum_t<E, string_view> {
|
||||||
using D = std::decay_t<E>;
|
using D = std::decay_t<E>;
|
||||||
using U = std::underlying_type_t<D>;
|
using U = std::underlying_type_t<D>;
|
||||||
static_assert(detail::nameof_enum_supported<D>::value, "nameof::nameof_enum unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(detail::nameof_enum_supported<D>::value,
|
||||||
|
"nameof::nameof_enum unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
static_assert(detail::count_v<D> > 0, "nameof::nameof_enum requires enum implementation and valid max and min.");
|
static_assert(detail::count_v<D> > 0, "nameof::nameof_enum requires enum implementation and valid max and min.");
|
||||||
|
|
||||||
if constexpr(detail::is_sparse_v<D>) {
|
if constexpr(detail::is_sparse_v<D>) {
|
||||||
|
@ -1074,7 +1152,8 @@ template <typename E>
|
||||||
template <typename E>
|
template <typename E>
|
||||||
[[nodiscard]] auto nameof_enum_or(E value, string_view default_value) -> detail::enable_if_enum_t<E, string> {
|
[[nodiscard]] auto nameof_enum_or(E value, string_view default_value) -> detail::enable_if_enum_t<E, string> {
|
||||||
using D = std::decay_t<E>;
|
using D = std::decay_t<E>;
|
||||||
static_assert(detail::nameof_enum_supported<D>::value, "nameof::nameof_enum_or unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(detail::nameof_enum_supported<D>::value,
|
||||||
|
"nameof::nameof_enum_or unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
static_assert(detail::count_v<D> > 0, "nameof::nameof_enum_or requires enum implementation and valid max and min.");
|
static_assert(detail::count_v<D> > 0, "nameof::nameof_enum_or requires enum implementation and valid max and min.");
|
||||||
|
|
||||||
if(auto v = nameof_enum<D>(value); !v.empty()) {
|
if(auto v = nameof_enum<D>(value); !v.empty()) {
|
||||||
|
@ -1088,7 +1167,8 @@ template <typename E>
|
||||||
[[nodiscard]] auto nameof_enum_flag(E value, char sep = '|') -> detail::enable_if_enum_t<E, string> {
|
[[nodiscard]] auto nameof_enum_flag(E value, char sep = '|') -> detail::enable_if_enum_t<E, string> {
|
||||||
using D = std::decay_t<E>;
|
using D = std::decay_t<E>;
|
||||||
using U = std::underlying_type_t<D>;
|
using U = std::underlying_type_t<D>;
|
||||||
static_assert(detail::nameof_enum_supported<D>::value, "nameof::nameof_enum_flag unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(detail::nameof_enum_supported<D>::value,
|
||||||
|
"nameof::nameof_enum_flag unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
static_assert(detail::count_v<D, true> > 0, "nameof::nameof_enum_flag requires enum-flags implementation.");
|
static_assert(detail::count_v<D, true> > 0, "nameof::nameof_enum_flag requires enum-flags implementation.");
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
|
@ -1119,7 +1199,8 @@ template <auto V, detail::enable_if_enum_t<decltype(V), int> = 0>
|
||||||
[[nodiscard]] constexpr auto nameof_enum() noexcept {
|
[[nodiscard]] constexpr auto nameof_enum() noexcept {
|
||||||
using D = std::decay_t<decltype(V)>;
|
using D = std::decay_t<decltype(V)>;
|
||||||
static_assert(std::is_enum_v<D>, "nameof::nameof_enum requires member enum type.");
|
static_assert(std::is_enum_v<D>, "nameof::nameof_enum requires member enum type.");
|
||||||
static_assert(detail::nameof_enum_supported<D>::value, "nameof::nameof_enum unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(detail::nameof_enum_supported<D>::value,
|
||||||
|
"nameof::nameof_enum unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
return detail::enum_name_v<D, V>;
|
return detail::enum_name_v<D, V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1127,7 +1208,8 @@ template <auto V, detail::enable_if_enum_t<decltype(V), int> = 0>
|
||||||
template <typename T>
|
template <typename T>
|
||||||
[[nodiscard]] constexpr string_view nameof_type() noexcept {
|
[[nodiscard]] constexpr string_view nameof_type() noexcept {
|
||||||
using U = detail::identity<detail::remove_cvref_t<T>>;
|
using U = detail::identity<detail::remove_cvref_t<T>>;
|
||||||
static_assert(detail::nameof_type_supported<U>::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(detail::nameof_type_supported<U>::value,
|
||||||
|
"nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
return detail::type_name_v<U>;
|
return detail::type_name_v<U>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1135,7 +1217,8 @@ template <typename T>
|
||||||
template <typename T>
|
template <typename T>
|
||||||
[[nodiscard]] constexpr string_view nameof_full_type() noexcept {
|
[[nodiscard]] constexpr string_view nameof_full_type() noexcept {
|
||||||
using U = detail::identity<T>;
|
using U = detail::identity<T>;
|
||||||
static_assert(detail::nameof_type_supported<U>::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(detail::nameof_type_supported<U>::value,
|
||||||
|
"nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
return detail::type_name_v<U>;
|
return detail::type_name_v<U>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1143,7 +1226,8 @@ template <typename T>
|
||||||
template <typename T, detail::enable_if_has_short_name_t<T, int> = 0>
|
template <typename T, detail::enable_if_has_short_name_t<T, int> = 0>
|
||||||
[[nodiscard]] constexpr auto nameof_short_type() noexcept {
|
[[nodiscard]] constexpr auto nameof_short_type() noexcept {
|
||||||
using U = detail::identity<detail::remove_cvref_t<T>>;
|
using U = detail::identity<detail::remove_cvref_t<T>>;
|
||||||
static_assert(detail::nameof_type_supported<U>::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(detail::nameof_type_supported<U>::value,
|
||||||
|
"nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
static_assert(!std::is_array_v<T> && !std::is_pointer_v<T>, "nameof::nameof_member requires non array and non pointer type.");
|
static_assert(!std::is_array_v<T> && !std::is_pointer_v<T>, "nameof::nameof_member requires non array and non pointer type.");
|
||||||
constexpr string_view name = detail::pretty_name(detail::type_name_v<U>);
|
constexpr string_view name = detail::pretty_name(detail::type_name_v<U>);
|
||||||
static_assert(!name.empty(), "Type does not have a short name.");
|
static_assert(!name.empty(), "Type does not have a short name.");
|
||||||
|
@ -1155,7 +1239,8 @@ template <auto V, std::enable_if_t<std::is_member_pointer_v<decltype(V)>, int> =
|
||||||
[[nodiscard]] constexpr auto nameof_member() noexcept {
|
[[nodiscard]] constexpr auto nameof_member() noexcept {
|
||||||
using U = decltype(V);
|
using U = decltype(V);
|
||||||
static_assert(std::is_member_pointer_v<U>, "nameof::nameof_member requires member pointer type.");
|
static_assert(std::is_member_pointer_v<U>, "nameof::nameof_member requires member pointer type.");
|
||||||
static_assert(detail::nameof_member_supported<U>::value, "nameof::nameof_member unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(detail::nameof_member_supported<U>::value,
|
||||||
|
"nameof::nameof_member unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
return detail::member_name_v<V>;
|
return detail::member_name_v<V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1164,85 +1249,15 @@ template <auto V, std::enable_if_t<std::is_pointer_v<decltype(V)>, int> = 0>
|
||||||
[[nodiscard]] constexpr auto nameof_pointer() noexcept {
|
[[nodiscard]] constexpr auto nameof_pointer() noexcept {
|
||||||
using U = decltype(V);
|
using U = decltype(V);
|
||||||
static_assert(std::is_pointer_v<U>, "nameof::nameof_pointer requires pointer type.");
|
static_assert(std::is_pointer_v<U>, "nameof::nameof_pointer requires pointer type.");
|
||||||
static_assert(detail::nameof_pointer_supported<U>::value, "nameof::nameof_pointer unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
static_assert(detail::nameof_pointer_supported<U>::value,
|
||||||
|
"nameof::nameof_pointer unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
|
||||||
return detail::pointer_name_v<V>;
|
return detail::pointer_name_v<V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMEOF_EXPORT_END
|
||||||
|
|
||||||
} // namespace nameof
|
} // namespace nameof
|
||||||
|
|
||||||
// Obtains name of variable, function, macro.
|
|
||||||
#define NAMEOF(...) []() constexpr noexcept { \
|
|
||||||
::std::void_t<decltype(__VA_ARGS__)>(); \
|
|
||||||
constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
|
|
||||||
static_assert(!_name.empty(), "Expression does not have a name."); \
|
|
||||||
constexpr auto _size = _name.size(); \
|
|
||||||
constexpr auto _nameof = ::nameof::cstring<_size>{_name}; \
|
|
||||||
return _nameof; }()
|
|
||||||
|
|
||||||
// Obtains full name of variable, function, macro.
|
|
||||||
#define NAMEOF_FULL(...) []() constexpr noexcept { \
|
|
||||||
::std::void_t<decltype(__VA_ARGS__)>(); \
|
|
||||||
constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__, false); \
|
|
||||||
static_assert(!_name.empty(), "Expression does not have a name."); \
|
|
||||||
constexpr auto _size = _name.size(); \
|
|
||||||
constexpr auto _nameof_full = ::nameof::cstring<_size>{_name}; \
|
|
||||||
return _nameof_full; }()
|
|
||||||
|
|
||||||
// Obtains raw name of variable, function, macro.
|
|
||||||
#define NAMEOF_RAW(...) []() constexpr noexcept { \
|
|
||||||
::std::void_t<decltype(__VA_ARGS__)>(); \
|
|
||||||
constexpr auto _name = ::nameof::string_view{#__VA_ARGS__}; \
|
|
||||||
static_assert(!_name.empty(), "Expression does not have a name."); \
|
|
||||||
constexpr auto _size = _name.size(); \
|
|
||||||
constexpr auto _nameof_raw = ::nameof::cstring<_size>{_name}; \
|
|
||||||
return _nameof_raw; }()
|
|
||||||
|
|
||||||
// Obtains name of enum variable.
|
|
||||||
#define NAMEOF_ENUM(...) ::nameof::nameof_enum<::std::decay_t<decltype(__VA_ARGS__)>>(__VA_ARGS__)
|
|
||||||
|
|
||||||
// Obtains name of enum variable or default value if enum variable out of range.
|
|
||||||
#define NAMEOF_ENUM_OR(...) ::nameof::nameof_enum_or(__VA_ARGS__)
|
|
||||||
|
|
||||||
// Obtains name of static storage enum variable.
|
|
||||||
// This version is much lighter on the compile times and is not restricted to the enum_range limitation.
|
|
||||||
#define NAMEOF_ENUM_CONST(...) ::nameof::nameof_enum<__VA_ARGS__>()
|
|
||||||
|
|
||||||
// Obtains name of enum-flags variable.
|
|
||||||
#define NAMEOF_ENUM_FLAG(...) ::nameof::nameof_enum_flag<::std::decay_t<decltype(__VA_ARGS__)>>(__VA_ARGS__)
|
|
||||||
|
|
||||||
// Obtains type name, reference and cv-qualifiers are ignored.
|
|
||||||
#define NAMEOF_TYPE(...) ::nameof::nameof_type<__VA_ARGS__>()
|
|
||||||
|
|
||||||
// Obtains full type name, with reference and cv-qualifiers.
|
|
||||||
#define NAMEOF_FULL_TYPE(...) ::nameof::nameof_full_type<__VA_ARGS__>()
|
|
||||||
|
|
||||||
// Obtains short type name.
|
|
||||||
#define NAMEOF_SHORT_TYPE(...) ::nameof::nameof_short_type<__VA_ARGS__>()
|
|
||||||
|
|
||||||
// Obtains type name of expression, reference and cv-qualifiers are ignored.
|
|
||||||
#define NAMEOF_TYPE_EXPR(...) ::nameof::nameof_type<decltype(__VA_ARGS__)>()
|
|
||||||
|
|
||||||
// Obtains full type name of expression, with reference and cv-qualifiers.
|
|
||||||
#define NAMEOF_FULL_TYPE_EXPR(...) ::nameof::nameof_full_type<decltype(__VA_ARGS__)>()
|
|
||||||
|
|
||||||
// Obtains short type name of expression.
|
|
||||||
#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<::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())
|
|
||||||
|
|
||||||
// Obtains short type name, using RTTI.
|
|
||||||
#define NAMEOF_SHORT_TYPE_RTTI(...) ::nameof::detail::nameof_short_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name())
|
|
||||||
|
|
||||||
// Obtains name of member.
|
|
||||||
#define NAMEOF_MEMBER(...) ::nameof::nameof_member<__VA_ARGS__>()
|
|
||||||
|
|
||||||
// Obtains name of a function, a global or class static variable.
|
|
||||||
#define NAMEOF_POINTER(...) ::nameof::nameof_pointer<__VA_ARGS__>()
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
|
|
149
include/nameof_macro.hpp
Normal file
149
include/nameof_macro.hpp
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
#ifndef NEARGYE_NAMEOF_MACRO_HPP
|
||||||
|
#define NEARGYE_NAMEOF_MACRO_HPP
|
||||||
|
|
||||||
|
// Checks nameof_type compiler compatibility.
|
||||||
|
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || defined(_MSC_VER) && _MSC_VER >= 1910
|
||||||
|
#undef NAMEOF_TYPE_SUPPORTED
|
||||||
|
#define NAMEOF_TYPE_SUPPORTED 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Checks nameof_type_rtti compiler compatibility.
|
||||||
|
#if defined(__clang__)
|
||||||
|
#if __has_feature(cxx_rtti)
|
||||||
|
#undef NAMEOF_TYPE_RTTI_SUPPORTED
|
||||||
|
#define NAMEOF_TYPE_RTTI_SUPPORTED 1
|
||||||
|
#endif
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#if defined(__GXX_RTTI)
|
||||||
|
#undef NAMEOF_TYPE_RTTI_SUPPORTED
|
||||||
|
#define NAMEOF_TYPE_RTTI_SUPPORTED 1
|
||||||
|
#endif
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#if defined(_CPPRTTI)
|
||||||
|
#undef NAMEOF_TYPE_RTTI_SUPPORTED
|
||||||
|
#define NAMEOF_TYPE_RTTI_SUPPORTED 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Checks nameof_member compiler compatibility.
|
||||||
|
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || \
|
||||||
|
defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 202002L
|
||||||
|
#undef NAMEOF_MEMBER_SUPPORTED
|
||||||
|
#define NAMEOF_MEMBER_SUPPORTED 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Checks nameof_pointer compiler compatibility.
|
||||||
|
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || \
|
||||||
|
defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 202002L
|
||||||
|
#undef NAMEOF_POINTER_SUPPORTED
|
||||||
|
#define NAMEOF_POINTER_SUPPORTED 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Checks nameof_enum compiler compatibility.
|
||||||
|
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER) && _MSC_VER >= 1910
|
||||||
|
#undef NAMEOF_ENUM_SUPPORTED
|
||||||
|
#define NAMEOF_ENUM_SUPPORTED 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Checks nameof_enum compiler aliases compatibility.
|
||||||
|
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER) && _MSC_VER >= 1920
|
||||||
|
#undef NAMEOF_ENUM_SUPPORTED_ALIASES
|
||||||
|
#define NAMEOF_ENUM_SUPPORTED_ALIASES 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Enum value must be greater or equals than NAMEOF_ENUM_RANGE_MIN. By default NAMEOF_ENUM_RANGE_MIN = -128.
|
||||||
|
// If need another min range for all enum types by default, redefine the macro NAMEOF_ENUM_RANGE_MIN.
|
||||||
|
#if !defined(NAMEOF_ENUM_RANGE_MIN)
|
||||||
|
#define NAMEOF_ENUM_RANGE_MIN -128
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Enum value must be less or equals than NAMEOF_ENUM_RANGE_MAX. By default NAMEOF_ENUM_RANGE_MAX = 128.
|
||||||
|
// If need another max range for all enum types by default, redefine the macro NAMEOF_ENUM_RANGE_MAX.
|
||||||
|
#if !defined(NAMEOF_ENUM_RANGE_MAX)
|
||||||
|
#define NAMEOF_ENUM_RANGE_MAX 128
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NAMEOF_VERSION_MAJOR 0
|
||||||
|
#define NAMEOF_VERSION_MINOR 10
|
||||||
|
#define NAMEOF_VERSION_PATCH 4
|
||||||
|
|
||||||
|
// Obtains name of variable, function, macro.
|
||||||
|
#define NAMEOF(...) \
|
||||||
|
[]() constexpr noexcept { \
|
||||||
|
::std::void_t<decltype(__VA_ARGS__)>(); \
|
||||||
|
constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
|
||||||
|
static_assert(!_name.empty(), "Expression does not have a name."); \
|
||||||
|
constexpr auto _size = _name.size(); \
|
||||||
|
constexpr auto _nameof = ::nameof::cstring<_size>{_name}; \
|
||||||
|
return _nameof; \
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Obtains full name of variable, function, macro.
|
||||||
|
#define NAMEOF_FULL(...) \
|
||||||
|
[]() constexpr noexcept { \
|
||||||
|
::std::void_t<decltype(__VA_ARGS__)>(); \
|
||||||
|
constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__, false); \
|
||||||
|
static_assert(!_name.empty(), "Expression does not have a name."); \
|
||||||
|
constexpr auto _size = _name.size(); \
|
||||||
|
constexpr auto _nameof_full = ::nameof::cstring<_size>{_name}; \
|
||||||
|
return _nameof_full; \
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Obtains raw name of variable, function, macro.
|
||||||
|
#define NAMEOF_RAW(...) \
|
||||||
|
[]() constexpr noexcept { \
|
||||||
|
::std::void_t<decltype(__VA_ARGS__)>(); \
|
||||||
|
constexpr auto _name = ::nameof::string_view{#__VA_ARGS__}; \
|
||||||
|
static_assert(!_name.empty(), "Expression does not have a name."); \
|
||||||
|
constexpr auto _size = _name.size(); \
|
||||||
|
constexpr auto _nameof_raw = ::nameof::cstring<_size>{_name}; \
|
||||||
|
return _nameof_raw; \
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Obtains name of enum variable.
|
||||||
|
#define NAMEOF_ENUM(...) ::nameof::nameof_enum<::std::decay_t<decltype(__VA_ARGS__)>>(__VA_ARGS__)
|
||||||
|
|
||||||
|
// Obtains name of enum variable or default value if enum variable out of range.
|
||||||
|
#define NAMEOF_ENUM_OR(...) ::nameof::nameof_enum_or(__VA_ARGS__)
|
||||||
|
|
||||||
|
// Obtains name of static storage enum variable.
|
||||||
|
// This version is much lighter on the compile times and is not restricted to the enum_range limitation.
|
||||||
|
#define NAMEOF_ENUM_CONST(...) ::nameof::nameof_enum<__VA_ARGS__>()
|
||||||
|
|
||||||
|
// Obtains name of enum-flags variable.
|
||||||
|
#define NAMEOF_ENUM_FLAG(...) ::nameof::nameof_enum_flag<::std::decay_t<decltype(__VA_ARGS__)>>(__VA_ARGS__)
|
||||||
|
|
||||||
|
// Obtains type name, reference and cv-qualifiers are ignored.
|
||||||
|
#define NAMEOF_TYPE(...) ::nameof::nameof_type<__VA_ARGS__>()
|
||||||
|
|
||||||
|
// Obtains full type name, with reference and cv-qualifiers.
|
||||||
|
#define NAMEOF_FULL_TYPE(...) ::nameof::nameof_full_type<__VA_ARGS__>()
|
||||||
|
|
||||||
|
// Obtains short type name.
|
||||||
|
#define NAMEOF_SHORT_TYPE(...) ::nameof::nameof_short_type<__VA_ARGS__>()
|
||||||
|
|
||||||
|
// Obtains type name of expression, reference and cv-qualifiers are ignored.
|
||||||
|
#define NAMEOF_TYPE_EXPR(...) ::nameof::nameof_type<decltype(__VA_ARGS__)>()
|
||||||
|
|
||||||
|
// Obtains full type name of expression, with reference and cv-qualifiers.
|
||||||
|
#define NAMEOF_FULL_TYPE_EXPR(...) ::nameof::nameof_full_type<decltype(__VA_ARGS__)>()
|
||||||
|
|
||||||
|
// Obtains short type name of expression.
|
||||||
|
#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<::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())
|
||||||
|
|
||||||
|
// Obtains short type name, using RTTI.
|
||||||
|
#define NAMEOF_SHORT_TYPE_RTTI(...) ::nameof::detail::nameof_short_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name())
|
||||||
|
|
||||||
|
// Obtains name of member.
|
||||||
|
#define NAMEOF_MEMBER(...) ::nameof::nameof_member<__VA_ARGS__>()
|
||||||
|
|
||||||
|
// Obtains name of a function, a global or class static variable.
|
||||||
|
#define NAMEOF_POINTER(...) ::nameof::nameof_pointer<__VA_ARGS__>()
|
||||||
|
|
||||||
|
#endif
|
46
src/nameof.cpp
Normal file
46
src/nameof.cpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
module;
|
||||||
|
|
||||||
|
#ifndef NAMEOF_IMPORT_STD
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <iosfwd>
|
||||||
|
#include <iterator>
|
||||||
|
#include <limits>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#if !defined(NAMEOF_USING_ALIAS_STRING)
|
||||||
|
#include <string>
|
||||||
|
#endif
|
||||||
|
#if !defined(NAMEOF_USING_ALIAS_STRING_VIEW)
|
||||||
|
#include <string_view>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __has_include(<cxxabi.h>)
|
||||||
|
#include <cxxabi.h>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
export module nameof;
|
||||||
|
|
||||||
|
#ifdef NAMEOF_IMPORT_STD
|
||||||
|
|
||||||
|
import std;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NAMEOF_ATTACH_TO_GLOBAL_MODULE
|
||||||
|
extern "C++" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <nameof.hpp>
|
||||||
|
|
||||||
|
#ifdef NAMEOF_ATTACH_TO_GLOBAL_MODULE
|
||||||
|
} // extern "C++"
|
||||||
|
#endif
|
Loading…
Reference in a new issue