diff --git a/doc/limitations.md b/doc/limitations.md index e0de6ab..482d13b 100644 --- a/doc/limitations.md +++ b/doc/limitations.md @@ -115,4 +115,4 @@ * Intellisense Visual Studio may have some problems analyzing `magic_enum`. * Enums in template may work incorrectly (especially on Сlang) - See (#164)[https://github.com/Neargye/magic_enum/issues/164], (#65)[https://github.com/Neargye/magic_enum/issues/65] + See (#164)[https://github.com/Neargye/magic_enum/issues/164], (#65)[https://github.com/Neargye/magic_enum/issues/65] diff --git a/include/magic_enum_format.hpp b/include/magic_enum_format.hpp index ec91c47..a90288a 100644 --- a/include/magic_enum_format.hpp +++ b/include/magic_enum_format.hpp @@ -32,13 +32,13 @@ #ifndef NEARGYE_MAGIC_ENUM_FORMAT_HPP #define NEARGYE_MAGIC_ENUM_FORMAT_HPP -#ifndef __cpp_lib_format +#if !defined(__cpp_lib_format) # error "Format is not supported" #endif #include "magic_enum.hpp" -#ifndef MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT +#if !defined(MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT) # define MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT true # define MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT_AUTO_DEFINE #endif // MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT @@ -53,25 +53,25 @@ namespace magic_enum::customize { #include -template +template struct std::formatter && magic_enum::customize::enum_format_enabled(), char>> : std::formatter { auto format(E e, format_context& ctx) { - if constexpr (magic_enum::detail::is_flags_v) { - if (auto name = magic_enum::enum_flags_name(e); !name.empty()) { + using D = std::decay_t; + if constexpr (magic_enum::detail::is_flags_v) { + if (auto name = magic_enum::enum_flags_name(e); !name.empty()) { return this->std::formatter::format(std::string_view{name.data(), name.size()}, ctx); } } else { - if (auto name = magic_enum::enum_name(e); !name.empty()) { + if (auto name = magic_enum::enum_name(e); !name.empty()) { return this->std::formatter::format(std::string_view{name.data(), name.size()}, ctx); } } constexpr auto type_name = magic_enum::enum_type_name(); - throw std::format_error("Type of " + std::string{type_name.data(), type_name.size()} + " enum value: " + - std::to_string(magic_enum::enum_integer(e)) + " is not exists."); + throw std::format_error("Type of " + std::string{type_name.data(), type_name.size()} + " enum value: " + std::to_string(magic_enum::enum_integer(e)) + " is not exists."); } }; -#ifdef MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT_AUTO_DEFINE +#if defined(MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT_AUTO_DEFINE) # undef MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT # undef MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT_AUTO_DEFINE #endif // MAGIC_ENUM_DEFAULT_ENABLE_ENUM_FORMAT_AUTO_DEFINE diff --git a/test/test.cpp b/test/test.cpp index b6a3276..7517c40 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1202,7 +1202,7 @@ TEST_CASE("multdimensional-switch-case") { #endif -#ifdef __cpp_lib_format +#if defined(__cpp_lib_format) #include @@ -1210,4 +1210,4 @@ TEST_CASE("format-base") { REQUIRE(std::format("Test-{:~^10}.", Color::RED) == "Test-~~~red~~~~."); } -#endif \ No newline at end of file +#endif diff --git a/test/test_flags.cpp b/test/test_flags.cpp index 29626c2..2773158 100644 --- a/test/test_flags.cpp +++ b/test/test_flags.cpp @@ -823,7 +823,7 @@ TEST_CASE("constexpr_for") { #endif -#ifdef __cpp_lib_format +#if defined(__cpp_lib_format) #include @@ -831,4 +831,4 @@ TEST_CASE("format-base") { REQUIRE(std::format("Test-{:~^11}.", Color::RED | Color::GREEN) == "Test-~RED|GREEN~."); } -#endif \ No newline at end of file +#endif