1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-09 23:34:23 +00:00

Support R++ builtins for type/enumerator name (#238)

This commit is contained in:
Alexander 2023-02-01 17:24:12 +03:00 committed by GitHub
parent 769506a8e6
commit 6527df91d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,7 +77,7 @@
#endif
// Checks magic_enum compiler compatibility.
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER) && _MSC_VER >= 1910
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER) && _MSC_VER >= 1910 || defined(__RESHARPER__)
# undef MAGIC_ENUM_SUPPORTED
# define MAGIC_ENUM_SUPPORTED 1
#endif
@ -100,6 +100,19 @@
# define MAGIC_ENUM_RANGE_MAX 128
#endif
// Improve ReSharper C++ intellisense performance with builtins, avoiding unnecessary template instantiations.
#if defined(__RESHARPER__)
# undef MAGIC_ENUM_GET_ENUM_NAME_BUILTIN
# undef MAGIC_ENUM_GET_TYPE_NAME_BUILTIN
# if __RESHARPER__ >= 20230100
# define MAGIC_ENUM_GET_ENUM_NAME_BUILTIN(V) __rscpp_enumerator_name(V)
# define MAGIC_ENUM_GET_TYPE_NAME_BUILTIN(T) __rscpp_type_name<T>()
# else
# define MAGIC_ENUM_GET_ENUM_NAME_BUILTIN(V) nullptr
# define MAGIC_ENUM_GET_TYPE_NAME_BUILTIN(T) nullptr
# endif
#endif
namespace magic_enum {
// If need another optional type, define the macro MAGIC_ENUM_USING_ALIAS_OPTIONAL.
@ -408,7 +421,10 @@ constexpr auto n() noexcept {
static_assert(is_enum_v<E>, "magic_enum::detail::n requires enum type.");
if constexpr (supported<E>::value) {
#if defined(__clang__) || defined(__GNUC__)
#if defined(MAGIC_ENUM_GET_TYPE_NAME_BUILTIN)
constexpr auto name_ptr = MAGIC_ENUM_GET_TYPE_NAME_BUILTIN(E);
constexpr auto name = name_ptr ? string_view{ name_ptr } : std::string_view{};
#elif defined(__clang__) || defined(__GNUC__)
constexpr auto name = pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2});
#elif defined(_MSC_VER)
constexpr auto name = pretty_name({__FUNCSIG__, sizeof(__FUNCSIG__) - 17});
@ -449,7 +465,10 @@ constexpr auto n() noexcept {
static_assert(is_enum_v<E>, "magic_enum::detail::n requires enum type.");
if constexpr (supported<E>::value) {
#if defined(__clang__) || defined(__GNUC__)
#if defined(MAGIC_ENUM_GET_ENUM_NAME_BUILTIN)
constexpr auto name_ptr = MAGIC_ENUM_GET_ENUM_NAME_BUILTIN(V);
constexpr auto name = name_ptr ? string_view{ name_ptr } : std::string_view{};
#elif defined(__clang__) || defined(__GNUC__)
constexpr auto name = pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2});
#elif defined(_MSC_VER)
constexpr auto name = pretty_name({__FUNCSIG__, sizeof(__FUNCSIG__) - 17});