Skip to content

Commit

Permalink
pre-rel 1.0i
Browse files Browse the repository at this point in the history
  • Loading branch information
David Dight committed Jul 11, 2024
1 parent 30f30de commit 479e1b8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions include/fix8/conjure_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,6 @@ class conjure_enum : public static_only
template<T e>
static consteval const char *epeek() noexcept { return std::source_location::current().function_name(); }

template<T e>
static constexpr std::string_view enum_to_string() noexcept { return _get_name<e>(); }

static constexpr std::string_view type_name() noexcept
{
constexpr std::string_view from{tpeek()};
Expand Down Expand Up @@ -372,6 +369,7 @@ class conjure_enum : public static_only

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

// scope ops
static constexpr std::string_view remove_scope(std::string_view what) noexcept
{
return _process_scope(rev_scoped_entries, what);
Expand All @@ -390,13 +388,15 @@ class conjure_enum : public static_only
return false;
}

// iterators
static constexpr auto cbegin() noexcept { return entries.cbegin(); }
static constexpr auto cend() noexcept { return entries.cend(); }
static constexpr auto crbegin() noexcept { return entries.crbegin(); }
static constexpr auto crend() noexcept { return entries.crend(); }
static constexpr auto front() noexcept { return *cbegin(); }
static constexpr auto back() noexcept { return *std::prev(cend()); }

// enum <==> int
static constexpr int enum_to_int(T value) noexcept
{
return static_cast<int>(value);
Expand All @@ -412,6 +412,8 @@ class conjure_enum : public static_only
return *result.first;
return {};
}

// contains
static constexpr bool contains(T value) noexcept
{
const auto result { std::equal_range(values.cbegin(), values.cend(), value, _value_comp) };
Expand All @@ -422,6 +424,11 @@ class conjure_enum : public static_only
const auto result { std::equal_range(sorted_entries.cbegin(), sorted_entries.cend(), enum_tuple(T{}, str), _tuple_comp_rev) };
return result.first != result.second;
}

// string <==> enum
template<T e>
static constexpr std::string_view enum_to_string() noexcept { return _get_name<e>(); }

static constexpr std::string_view enum_to_string(T value, bool noscope=false) noexcept
{
if (const auto result { std::equal_range(entries.cbegin(), entries.cend(), enum_tuple(value, std::string_view()), _tuple_comp) };
Expand Down Expand Up @@ -519,6 +526,7 @@ class conjure_enum : public static_only
return result.first != result.second ? std::invoke(std::get<Fn>(*result.first), obj, ev, std::forward<Args>(args)...)
: std::invoke(std::get<Fn>(*std::prev(disp.cend())), obj, ev, std::forward<Args>(args)...);
}

// public constexpr data structures
static constexpr auto values { _values() };
static constexpr auto entries { _entries(std::make_index_sequence<values.size()>()) };
Expand Down Expand Up @@ -809,6 +817,8 @@ constexpr enum_bitset<T> operator^(const enum_bitset<T>& lh, const enum_bitset<T
{ return lh.operator^(rh.to_ulong()); }

//-----------------------------------------------------------------------------------------
// General purpose class allowing you to extract a string representation of any typename.
// The string will be stored statically by the compiler, so you can use the statically generated value `name` to obtain your type.
//-----------------------------------------------------------------------------------------
template<typename T>
class conjure_type : public static_only
Expand Down

0 comments on commit 479e1b8

Please sign in to comment.