From 1d114560b334d1905797769612b7df6257361005 Mon Sep 17 00:00:00 2001 From: David Dight Date: Tue, 9 Jul 2024 16:08:18 +1000 Subject: [PATCH 1/4] updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9aa5fc..ae2ce80 100644 --- a/README.md +++ b/README.md @@ -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** From 2af8c33fbb5e31d0b1995d3e360225ad9b2e003c Mon Sep 17 00:00:00 2001 From: David Dight Date: Tue, 9 Jul 2024 06:51:13 +0000 Subject: [PATCH 2/4] updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae2ce80..48bf236 100644 --- a/README.md +++ b/README.md @@ -810,8 +810,8 @@ std::cout << conjure_enum::epeek() << '\n'; ``` Generates this output with gcc: ```CSV -static consteval const char* FIX8::conjure_enum::epeek() [with T e = component::path; T = component] static consteval const char* FIX8::conjure_enum::tpeek() [with T = component] +static consteval const char* FIX8::conjure_enum::epeek() [with T e = component::path; T = component] ``` --- # 4. API and Examples using `enum_bitset` From 30f30de1f608a03b441d6f486d24c475a70306cb Mon Sep 17 00:00:00 2001 From: David Dight Date: Thu, 11 Jul 2024 07:59:35 +0000 Subject: [PATCH 3/4] updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48bf236..b85ef43 100644 --- a/README.md +++ b/README.md @@ -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`. From 479e1b80a0e21b75d906da3cc04917e9c4a4af29 Mon Sep 17 00:00:00 2001 From: David Dight Date: Thu, 11 Jul 2024 07:59:57 +0000 Subject: [PATCH 4/4] pre-rel 1.0i --- include/fix8/conjure_enum.hpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/fix8/conjure_enum.hpp b/include/fix8/conjure_enum.hpp index 8177ee1..8dd0d5d 100644 --- a/include/fix8/conjure_enum.hpp +++ b/include/fix8/conjure_enum.hpp @@ -332,9 +332,6 @@ class conjure_enum : public static_only template static consteval const char *epeek() noexcept { return std::source_location::current().function_name(); } - template - static constexpr std::string_view enum_to_string() noexcept { return _get_name(); } - static constexpr std::string_view type_name() noexcept { constexpr std::string_view from{tpeek()}; @@ -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); @@ -390,6 +388,7 @@ 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(); } @@ -397,6 +396,7 @@ class conjure_enum : public static_only 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(value); @@ -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) }; @@ -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 + static constexpr std::string_view enum_to_string() noexcept { return _get_name(); } + 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) }; @@ -519,6 +526,7 @@ class conjure_enum : public static_only return result.first != result.second ? std::invoke(std::get(*result.first), obj, ev, std::forward(args)...) : std::invoke(std::get(*std::prev(disp.cend())), obj, ev, std::forward(args)...); } + // public constexpr data structures static constexpr auto values { _values() }; static constexpr auto entries { _entries(std::make_index_sequence()) }; @@ -809,6 +817,8 @@ constexpr enum_bitset operator^(const enum_bitset& lh, const enum_bitset class conjure_type : public static_only