Skip to content

Commit

Permalink
pre-v1.0g-update
Browse files Browse the repository at this point in the history
  • Loading branch information
dakka committed Apr 8, 2024
1 parent 2c9d151 commit 6c4f627
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 0 additions & 2 deletions examples/unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ enum class numbers : int { zero, one, two, three, four, five, FIVE=five, six, se
TEST_CASE("is_valid")
{
REQUIRE(conjure_enum<component>::is_valid<component::password>());
REQUIRE(conjure_enum<component&>::is_valid<component::password>());
REQUIRE(!conjure_enum<component>::is_valid<static_cast<component>(100)>());
REQUIRE(conjure_enum<component1>::is_valid<password>());
REQUIRE(!conjure_enum<component1>::is_valid<static_cast<component1>(100)>());
Expand Down Expand Up @@ -260,7 +259,6 @@ TEST_CASE("for_each")
TEST_CASE("enum_bitset")
{
enum_bitset<numbers> eb;
//enum_bitset<numbers&> ebr;
eb.set_all<numbers::zero,numbers::two,numbers::five,numbers::nine>();
REQUIRE(eb.test_all<numbers::zero,numbers::two,numbers::five,numbers::nine>());
eb.reset<numbers::FIVE>(); // use alias
Expand Down
23 changes: 13 additions & 10 deletions include/fix8/conjure_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
// static const char *FIX8::conjure_enum<component>::tpeek() [T = component]
// |<-- -->|
// gcc
// static consteval const char* FIX8::conjure_enum<E, T>::epeek() [with T e = component::path; E = component; T = component] // valid
// |<-- -->|
// static consteval const char* FIX8::conjure_enum<E, T>::epeek() [with T e = (component)100; E = component; T = component] // invalid
// |<-- -->|
// static consteval const char* FIX8::conjure_enum<T>::epeek() [with T e = component::path; T = component] // valid
// |<-- -->|
// static consteval const char* FIX8::conjure_enum<T>::epeek() [with T e = (component)100; T = component] // invalid
// |<-- -->|
// static consteval const char* FIX8::conjure_type<T>::tpeek() [with T = component]
// |<-- -->|
// msvc
Expand Down Expand Up @@ -120,8 +120,8 @@ constexpr auto get_spec() noexcept
}

//-----------------------------------------------------------------------------------------
template<typename E, typename T=std::decay_t<E>>
requires std::is_enum_v<T>
template<typename T>
requires std::same_as<T, std::decay_t<T>> && std::is_enum_v<T>
class conjure_enum final
{
static constexpr int enum_min_value{ENUM_MIN_VALUE}, enum_max_value{ENUM_MAX_VALUE};
Expand Down Expand Up @@ -219,7 +219,7 @@ class conjure_enum final
static constexpr std::string_view _get_name() noexcept
{
constexpr std::string_view from{epeek<e>()};
if (constexpr auto ep { from.rfind(get_spec<0,0>()) }; ep != std::string_view::npos && from[ep + get_spec<0,0>().size()] != '(')
if constexpr (constexpr auto ep { from.rfind(get_spec<0,0>()) }; ep != std::string_view::npos && from[ep + get_spec<0,0>().size()] != '(')
{
constexpr std::string_view result { from.substr(ep + get_spec<0,0>().size()) };
if constexpr (constexpr auto lc { result.find_first_of(get_spec<1,0>()) }; lc != std::string_view::npos)
Expand Down Expand Up @@ -262,8 +262,9 @@ class conjure_enum final
}

struct is_scoped : std::integral_constant<bool, requires
{ requires !std::is_convertible_v<T, std::underlying_type_t<T>>; }>
{};
{
requires !std::convertible_to<T, std::underlying_type_t<T>>;
}>{};

template<T e>
static constexpr bool is_valid() noexcept { return !_get_name<e>().empty(); }
Expand Down Expand Up @@ -376,8 +377,10 @@ struct iterator_adaptor
// Note: your enum sequence must be continuous with the last enum value < count of enumerations
//-----------------------------------------------------------------------------------------
template<typename T>
concept valid_bitset_enum = std::is_enum_v<std::decay_t<T>> && requires(T)
concept valid_bitset_enum = requires(T)
{
requires std::is_enum_v<T>;
requires std::same_as<T, std::decay_t<T>>;
requires conjure_enum<T>::count() > 0;
requires static_cast<std::size_t>(conjure_enum<T>::values.back()) < conjure_enum<T>::count();
};
Expand Down

0 comments on commit 6c4f627

Please sign in to comment.