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 6c4f627 commit a220cdc
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions include/fix8/conjure_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ class conjure_enum final
return std::array<std::string_view, sizeof...(I)>{{{ _enum_name_v<values[I]>}...}};
}

template<T e>
static constexpr bool _is_valid() noexcept
{
constexpr std::string_view from{epeek<e>()};
if constexpr (constexpr auto ep { from.rfind(get_spec<0,0>()) }; ep != std::string_view::npos && from[ep + get_spec<0,0>().size()] != '('
&& from.substr(ep + get_spec<0,0>().size()).find_first_of(get_spec<1,0>()) != std::string_view::npos)
return true;
else
return false;
}

#if defined(__clang__) && defined(__apple_build_version__) // std::count_if not constexpr in xcode/clang
template<std::size_t N>
static constexpr auto count_if_constexpr(const bool (&valid)[N]) noexcept
Expand All @@ -196,10 +207,10 @@ class conjure_enum final
static constexpr auto _values(std::index_sequence<I...>) noexcept
{
#if defined(__clang__) && defined(__apple_build_version__)
constexpr bool valid[sizeof...(I)] { is_valid<static_cast<T>(enum_min_value + I)>()... };
constexpr bool valid[sizeof...(I)] { _is_valid<static_cast<T>(enum_min_value + I)>()... };
constexpr auto num_valid { count_if_constexpr(valid) };
#else
constexpr std::array<bool, sizeof...(I)> valid { is_valid<static_cast<T>(enum_min_value + I)>()... };
constexpr std::array<bool, sizeof...(I)> valid { _is_valid<static_cast<T>(enum_min_value + I)>()... };
constexpr auto num_valid { std::count_if(valid.cbegin(), valid.cend(), [](bool val) noexcept { return val; }) };
#endif
static_assert(num_valid > 0, "conjure_enum requires non-empty enum");
Expand All @@ -225,7 +236,8 @@ class conjure_enum final
if constexpr (constexpr auto lc { result.find_first_of(get_spec<1,0>()) }; lc != std::string_view::npos)
return result.substr(0, lc);
}
return {};
else
return {};
}

static constexpr bool value_comp(const T& pl, const T& pr) noexcept
Expand Down Expand Up @@ -258,7 +270,8 @@ class conjure_enum final
if constexpr (constexpr auto lc { result.find_first_of(get_spec<1,1>()) }; lc != std::string_view::npos)
return result.substr(0, lc);
}
return {};
else
return {};
}

struct is_scoped : std::integral_constant<bool, requires
Expand All @@ -267,7 +280,7 @@ class conjure_enum final
}>{};

template<T e>
static constexpr bool is_valid() noexcept { return !_get_name<e>().empty(); }
static constexpr bool is_valid() noexcept { return _is_valid<e>(); }

static constexpr auto count() noexcept { return values.size(); }

Expand Down

0 comments on commit a220cdc

Please sign in to comment.