Skip to content

Commit

Permalink
pre-v1.0b-update
Browse files Browse the repository at this point in the history
  • Loading branch information
dakka committed Mar 31, 2024
1 parent 9f22e83 commit 0840304
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]:&copy; 2024 Fix8 Market Technologies Pty Ltd, David L. Dight.
[^2]:&copy; 2019 - 2024 Daniil Goncharov
58 changes: 24 additions & 34 deletions include/fix8/conjure_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::tuple<std::string_view, char>>
({
#if defined __clang__
{ "e = ", ']' }, { "T = ", ']' },
#elif defined __GNUC__
{ "e = ", ';' }, { "T = ", ']' },
#elif defined _MSC_VER
{ "epeek<", '>' }, { "enum ", '>' },
#else
# error "compiler not supported"
#endif
})
};
template<int N, int V> // can't have constexpr decompositions! (but why?)
static constexpr auto gpos() noexcept { return std::get<N>(specifics[V]); }

template<T e>
static constexpr auto enum_name() noexcept
{
Expand Down Expand Up @@ -164,29 +182,12 @@ class conjure_enum
|<-- -->|
*/
constexpr std::string_view from{epeek<e>()};
#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 {};
}

Expand Down Expand Up @@ -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 {};
}

Expand Down

0 comments on commit 0840304

Please sign in to comment.