Replace union type holder to template extern variable (#62)
This commit is contained in:
parent
f2522c2cc0
commit
8aeb677413
1 changed files with 11 additions and 11 deletions
|
@ -968,7 +968,8 @@ 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__, sizeof(__FUNCSIG__) - 17});
|
constexpr auto name = pretty_name({__FUNCSIG__,
|
||||||
|
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
|
||||||
|
@ -986,26 +987,25 @@ template <typename From, typename Type>
|
||||||
From get_base_type(Type From::*);
|
From get_base_type(Type From::*);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
union union_type {
|
extern T nonexist_object;
|
||||||
constexpr ~union_type() {}
|
|
||||||
char c = {};
|
template<class T>
|
||||||
T f;
|
struct Store {
|
||||||
|
T v;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template<class T>
|
||||||
struct union_type_holder {
|
Store(T) -> Store<T>;
|
||||||
constexpr static union_type<T> value;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <auto V>
|
template <auto V>
|
||||||
constexpr auto get_member_name() noexcept {
|
consteval auto get_member_name() noexcept {
|
||||||
if constexpr (std::is_member_function_pointer_v<decltype(V)>) {
|
if constexpr (std::is_member_function_pointer_v<decltype(V)>) {
|
||||||
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, &(union_type_holder<decltype(get_base_type(V))>::value.f.*V)>();
|
return n<V, Store{&(nonexist_object<decltype(get_base_type(V))>.*V)}>();
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue