diff --git a/README.md b/README.md index 283c9dd6..eb34a7a4 100644 --- a/README.md +++ b/README.md @@ -970,7 +970,7 @@ It can be observed that there is only one copy of the scoped or unscoped enum va | :--- | :--- | :--- | ---: | | gcc | `11`, `12`, `13`| `std::format` not complete in `11`, `12` | `<= 10` | | clang | `15`, `16`| Catch2 needs `cxx_std_20` in `15` | `<= 14` | -| msvc | `17` | Visual Studio 2022, `17.9.5`| `<= 16`| +| msvc | `16`, `17` | Visual Studio 2019,2022, latest `17.9.5`| `<= 16.10`| [^1]:© 2024 Fix8 Market Technologies Pty Ltd, David L. Dight. [^2]:© 2019 - 2024 Daniil Goncharov diff --git a/include/fix8/conjure_enum.hpp b/include/fix8/conjure_enum.hpp index b73c0ea2..00737ea9 100644 --- a/include/fix8/conjure_enum.hpp +++ b/include/fix8/conjure_enum.hpp @@ -83,6 +83,24 @@ class conjure_enum static constexpr int enum_min_value{ENUM_MIN_VALUE}, enum_max_value{ENUM_MAX_VALUE}; static_assert(enum_max_value > enum_min_value, "enum_max_value must be greater than enum_min_value"); + static constexpr auto specifics + { + std::to_array> + ({ +#if defined __clang__ + { "e = ", ']' }, { "T = ", ']' }, +#elif defined __GNUC__ + { "e = ", ';' }, { "T = ", ']' }, +#elif defined _MSC_VER + { "epeek<", '>' }, { "enum ", '>' }, +#else +# error "compiler not supported" +#endif + }) + }; + template // can't have constexpr decompositions! (but why?) + static constexpr auto gpos() noexcept { return std::get(specifics[V]); } + template static constexpr auto enum_name() noexcept { @@ -164,29 +182,12 @@ class conjure_enum |<-- -->| */ constexpr std::string_view from{epeek()}; -#if defined __clang__ || defined __GNUC__ - if (constexpr auto ep { from.rfind("e = ") }; ep != std::string_view::npos && from[ep + 4] != '(') - { - constexpr std::string_view result { from.substr(ep + 4) }; -#if defined __clang__ -# define ptrm (']') -#else -# define ptrm (';') -#endif - if (constexpr auto lc { result.find_first_of(ptrm) }; lc != std::string_view::npos) - return result.substr(0, lc); -#undef ptrm - } -#elif defined _MSC_VER - if (constexpr auto ep { from.find("epeek<") }; ep != std::string_view::npos && from[ep + 6] != '(') + if (constexpr auto ep { from.rfind(gpos<0,0>()) }; ep != std::string_view::npos && from[ep + gpos<0,0>().size()] != '(') { - constexpr std::string_view result { from.substr(ep + 6) }; - if (constexpr auto lc { result.find_first_of('>') }; lc != std::string_view::npos) + constexpr std::string_view result { from.substr(ep + gpos<0,0>().size()) }; + if (constexpr auto lc { result.find_first_of(gpos<1,0>()) }; lc != std::string_view::npos) return result.substr(0, lc); } -#else -# error "compiler not supported" -#endif return {}; } @@ -228,23 +229,12 @@ class conjure_enum |<-- -->| */ constexpr std::string_view from{tpeek()}; -#if defined __clang__ || defined __GNUC__ - if (constexpr auto ep { from.rfind("T = ") }; ep != std::string_view::npos) - { - constexpr std::string_view result { from.substr(ep + 4) }; - if (constexpr auto lc { result.find_first_of(']') }; lc != std::string_view::npos) - return result.substr(0, lc); - } -#elif defined _MSC_VER - if (constexpr auto ep { from.find("enum ") }; ep != std::string_view::npos) + if (constexpr auto ep { from.rfind(gpos<0,1>()) }; ep != std::string_view::npos) { - constexpr std::string_view result { from.substr(ep + 5) }; - if (constexpr auto lc { result.find_first_of('>') }; lc != std::string_view::npos) + constexpr std::string_view result { from.substr(ep + gpos<0,1>().size()) }; + if (constexpr auto lc { result.find_first_of(gpos<1,1>()) }; lc != std::string_view::npos) return result.substr(0, lc); } -#else -# error "compiler not supported" -#endif return {}; }