Skip to content

Commit

Permalink
Merge pull request #10 from fix8mt/dev
Browse files Browse the repository at this point in the history
main to commitpush "pre-rel 1.0i"
  • Loading branch information
dakka authored Jul 11, 2024
2 parents 8166a13 + 479e1b8 commit 45a9d09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ unlocked the potential of `constexpr` algorithms and concepts. This translates t

- ***Lightweight***: Designed for performance without additional overhead
- ***Single Header-Only***: No external dependencies, simplifying integration into your project
- ***Modern C++20***: Entirely `constexpr` for compile-time safety, efficiency and performance
- ***Modern C++20***: Entirely `constexpr` for compile-time safety, efficiency and performance; no macros
- ***Broad Support***: Works with:
- scoped and unscoped enums
- enums with **aliases** and **gaps**
Expand Down Expand Up @@ -550,7 +550,7 @@ Optionally provide any additional parameters. Works with lambdas, member functio
There are two versions of `dispatch` - the first takes an enum value, a 'not found' value, and a `std::array` of `std::tuple` of enum and invocable.
The second version takes an enum value, and a `std::array` of `std::tuple` of enum and invocable. The last element of the array is called if the enum is not found.
This version is intended for use with `void` return invocables.
The second version of each of the above is intended to be used when using a member function - the _second_ parameter passed by your call must be the `this` pointer of the object.
The second version of each of the above is intended to be used when using a member function - the _first_ parameter passed after your array must be the `this` pointer of the object.
You can also use `std::bind` to bind the this pointer and any parameter placeholders when declaring your array.
If you wish to pass a `reference` parameter, you must wrap it in `std::ref`.
Expand Down Expand Up @@ -810,8 +810,8 @@ std::cout << conjure_enum<component>::epeek<component::scheme>() << '\n';
```
Generates this output with gcc:
```CSV
static consteval const char* FIX8::conjure_enum<T>::epeek() [with T e = component::path; T = component]
static consteval const char* FIX8::conjure_enum<T>::tpeek() [with T = component]
static consteval const char* FIX8::conjure_enum<T>::epeek() [with T e = component::path; T = component]
```
---
# 4. API and Examples using `enum_bitset`
Expand Down
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 45a9d09

Please sign in to comment.