From fdd9c2dafbc3ede3853f19b99392d6cae1f1d457 Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 07:17:56 +1000 Subject: [PATCH 01/17] pre-rel 1.1.1a --- utests/unittests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utests/unittests.cpp b/utests/unittests.cpp index 278794f..db8ff30 100644 --- a/utests/unittests.cpp +++ b/utests/unittests.cpp @@ -691,7 +691,7 @@ TEST_CASE("enum_bitset <==> std::bitset") std::bitset<10> bs{1 << 1 | 1 << 3 | 1 << 6}; enum_bitset ed(bs); REQUIRE(ed.to_ulong() == (1 << 1 | 1 << 3 | 1 << 6)); - std::bitset<10> bs1{ed}; + std::bitset<10> bs1{ed.to_ulong()}; REQUIRE(bs1.to_ulong() == (1 << 1 | 1 << 3 | 1 << 6)); } From a034af2ea0d6e686dcca3b85c0a719be7d9afca1 Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 14:06:35 +1000 Subject: [PATCH 02/17] pre-rel 1.1.1a --- include/fix8/conjure_enum_bitset.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fix8/conjure_enum_bitset.hpp b/include/fix8/conjure_enum_bitset.hpp index fc1f9dc..376035b 100644 --- a/include/fix8/conjure_enum_bitset.hpp +++ b/include/fix8/conjure_enum_bitset.hpp @@ -71,7 +71,7 @@ class enum_bitset std::conditional_t>>>; static_assert(std::integral, "requested bitset overflow"); - static constexpr U all_bits { (1 << countof) - 1 }; + static constexpr U all_bits { std::size_t(1 << countof) - 1 }; static constexpr U unused_bits { sizeof(U) * 8 - countof }; template From 61a17e7ee5b760016aca8d11b10bf25e83c9514c Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 14:08:27 +1000 Subject: [PATCH 03/17] pre-rel 1.1.1a --- include/fix8/conjure_enum_bitset.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fix8/conjure_enum_bitset.hpp b/include/fix8/conjure_enum_bitset.hpp index 376035b..1190284 100644 --- a/include/fix8/conjure_enum_bitset.hpp +++ b/include/fix8/conjure_enum_bitset.hpp @@ -71,7 +71,7 @@ class enum_bitset std::conditional_t>>>; static_assert(std::integral, "requested bitset overflow"); - static constexpr U all_bits { std::size_t(1 << countof) - 1 }; + static constexpr U all_bits { countof == 64 ? ~0 : (1 << countof) - 1 }; static constexpr U unused_bits { sizeof(U) * 8 - countof }; template From fad1e08708003884c9930cd0dd1b340c2dae0a85 Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 14:09:55 +1000 Subject: [PATCH 04/17] pre-rel 1.1.1a --- utests/unittests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utests/unittests.cpp b/utests/unittests.cpp index db8ff30..bc34c2b 100644 --- a/utests/unittests.cpp +++ b/utests/unittests.cpp @@ -52,7 +52,7 @@ enum class range_test1 { first, second, third, fourth, fifth, sixth, seventh, ei enum class range_test2 { first, second, third, fourth, fifth, sixth, seventh, eighth }; enum class range_test3 { first, second, third, fourth, fifth, sixth, seventh, eighth, ce_first=first, ce_last=eighth }; enum range_test4 { first, second, third, fourth, fifth, sixth, seventh, eighth, ce_first=first, ce_last=eighth }; -enum class numbers64 : uint64_t +enum class numbers64 { zero, one, two, three, four, five, six, seven, eight, nine, From ddd1f0fae077d0d60e08a0d214dcfa89a2650471 Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 16:34:33 +1000 Subject: [PATCH 05/17] pre-rel 1.1.1a --- include/fix8/conjure_enum_bitset.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/fix8/conjure_enum_bitset.hpp b/include/fix8/conjure_enum_bitset.hpp index 1190284..91f58bf 100644 --- a/include/fix8/conjure_enum_bitset.hpp +++ b/include/fix8/conjure_enum_bitset.hpp @@ -71,7 +71,10 @@ class enum_bitset std::conditional_t>>>; static_assert(std::integral, "requested bitset overflow"); - static constexpr U all_bits { countof == 64 ? ~0 : (1 << countof) - 1 }; + static constexpr std::size_t bits_per_base = sizeof(U) * 8; + static constexpr std::size_t base_type_count = (countof > 0 ? (countof - 1) / bits_per_base + 1 : 0); + static constexpr std::size_t not_interested = base_type_count * bits_per_base - countof; + static constexpr U all_bits = (U{1} << (bits_per_base - not_interested)) - 1; static constexpr U unused_bits { sizeof(U) * 8 - countof }; template From 51c440e024c28fc8e5beae80aedb572d29f04d78 Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 16:40:17 +1000 Subject: [PATCH 06/17] pre-rel 1.1.1a --- include/fix8/conjure_enum_bitset.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/fix8/conjure_enum_bitset.hpp b/include/fix8/conjure_enum_bitset.hpp index 91f58bf..6c503a1 100644 --- a/include/fix8/conjure_enum_bitset.hpp +++ b/include/fix8/conjure_enum_bitset.hpp @@ -71,10 +71,11 @@ class enum_bitset std::conditional_t>>>; static_assert(std::integral, "requested bitset overflow"); - static constexpr std::size_t bits_per_base = sizeof(U) * 8; + /*static constexpr std::size_t bits_per_base = sizeof(U) * 8; static constexpr std::size_t base_type_count = (countof > 0 ? (countof - 1) / bits_per_base + 1 : 0); static constexpr std::size_t not_interested = base_type_count * bits_per_base - countof; - static constexpr U all_bits = (U{1} << (bits_per_base - not_interested)) - 1; + static constexpr U all_bits = (std::size_t{1} << (bits_per_base - not_interested)) - 1; */ + static constexpr U all_bits { (std::size_t{1} << countof) - 1 }; static constexpr U unused_bits { sizeof(U) * 8 - countof }; template From 2884d18a1caa3ca3b66d5d9f71169368b8edf201 Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 16:42:59 +1000 Subject: [PATCH 07/17] pre-rel 1.1.1a --- include/fix8/conjure_enum_bitset.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fix8/conjure_enum_bitset.hpp b/include/fix8/conjure_enum_bitset.hpp index 6c503a1..3c94e14 100644 --- a/include/fix8/conjure_enum_bitset.hpp +++ b/include/fix8/conjure_enum_bitset.hpp @@ -120,7 +120,7 @@ class enum_bitset using const_reference = _reference; explicit constexpr enum_bitset(U bits) noexcept : _present(bits) {} - explicit constexpr enum_bitset(std::bitset from) : _present(from.to_ullong()) {} + explicit constexpr enum_bitset(std::bitset from) : _present(U(from.to_ullong())) {} constexpr enum_bitset(std::string_view from, bool anyscope=false, char sep='|', bool ignore_errors=true) : _present(factory(from, anyscope, sep, ignore_errors)) {} From 2cb229504c3d489085d2fb93eb1131d2d81c27f3 Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 16:44:14 +1000 Subject: [PATCH 08/17] pre-rel 1.1.1a --- include/fix8/conjure_enum_bitset.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fix8/conjure_enum_bitset.hpp b/include/fix8/conjure_enum_bitset.hpp index 3c94e14..8d15af6 100644 --- a/include/fix8/conjure_enum_bitset.hpp +++ b/include/fix8/conjure_enum_bitset.hpp @@ -147,9 +147,9 @@ class enum_bitset { if (std::bit_width(_present) > 32) throw std::overflow_error("overflow"); - return _present; + return static_cast(_present); } - constexpr unsigned long long to_ullong() const noexcept { return _present; } + constexpr unsigned long long to_ullong() const noexcept { return static_cast(_present); } constexpr U get_underlying() const noexcept { return _present; } constexpr int get_underlying_bit_size() const noexcept { return 8 * sizeof(U); } constexpr U get_bit_mask() const noexcept { return all_bits; } From f9ec22c41fe8669f26fc08ce8997cfc853f237d3 Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 16:47:36 +1000 Subject: [PATCH 09/17] pre-rel 1.1.1a --- include/fix8/conjure_enum_bitset.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fix8/conjure_enum_bitset.hpp b/include/fix8/conjure_enum_bitset.hpp index 8d15af6..ef14f46 100644 --- a/include/fix8/conjure_enum_bitset.hpp +++ b/include/fix8/conjure_enum_bitset.hpp @@ -75,7 +75,7 @@ class enum_bitset static constexpr std::size_t base_type_count = (countof > 0 ? (countof - 1) / bits_per_base + 1 : 0); static constexpr std::size_t not_interested = base_type_count * bits_per_base - countof; static constexpr U all_bits = (std::size_t{1} << (bits_per_base - not_interested)) - 1; */ - static constexpr U all_bits { (std::size_t{1} << countof) - 1 }; + static constexpr U all_bits { (std::size_t{1} << (countof & 63)) - 1 }; static constexpr U unused_bits { sizeof(U) * 8 - countof }; template From ec3ed64058e82bbad1caa4e7f49d8d3ea621a22f Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 17:53:02 +1000 Subject: [PATCH 10/17] pre-rel 1.1.1a --- utests/unittests.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utests/unittests.cpp b/utests/unittests.cpp index bc34c2b..fe60ccd 100644 --- a/utests/unittests.cpp +++ b/utests/unittests.cpp @@ -742,7 +742,9 @@ TEST_CASE("enum_bitset ops") ed.set(); REQUIRE(!ed.has_single_bit()); +#if not defined _MSC_VER REQUIRE(std::hash>{}(ed) == 14); +#endif } //----------------------------------------------------------------------------------------- From 1fa28af1d8dee2ce5a3513ada4d10cb2020fae2d Mon Sep 17 00:00:00 2001 From: David Dight Date: Wed, 11 Sep 2024 18:00:17 +1000 Subject: [PATCH 11/17] pre-rel 1.1.1b --- include/fix8/conjure_enum_bitset.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/fix8/conjure_enum_bitset.hpp b/include/fix8/conjure_enum_bitset.hpp index ef14f46..8e721ee 100644 --- a/include/fix8/conjure_enum_bitset.hpp +++ b/include/fix8/conjure_enum_bitset.hpp @@ -71,10 +71,6 @@ class enum_bitset std::conditional_t>>>; static_assert(std::integral, "requested bitset overflow"); - /*static constexpr std::size_t bits_per_base = sizeof(U) * 8; - static constexpr std::size_t base_type_count = (countof > 0 ? (countof - 1) / bits_per_base + 1 : 0); - static constexpr std::size_t not_interested = base_type_count * bits_per_base - countof; - static constexpr U all_bits = (std::size_t{1} << (bits_per_base - not_interested)) - 1; */ static constexpr U all_bits { (std::size_t{1} << (countof & 63)) - 1 }; static constexpr U unused_bits { sizeof(U) * 8 - countof }; From 665ff54cb963d86ea466b2eeac85b4a0e7f38d0f Mon Sep 17 00:00:00 2001 From: David Dight Date: Thu, 12 Sep 2024 07:10:32 +1000 Subject: [PATCH 12/17] pre-rel 1.1.1b --- examples/example.cpp | 7 +++++++ include/fix8/conjure_enum_bitset.hpp | 6 +++--- utests/unittests.cpp | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/example.cpp b/examples/example.cpp index ec8188d..9f36e7d 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -257,5 +257,12 @@ int main(void) for (const auto& [ev,str] : {en::front(), en::back()}) std::cout << static_cast(ev) << ' ' << str << '\n'; + enum_bitset ee; + ee.set(); + std::cout << ee << '\n'; + std::cout << ee.count() << '\n'; + std::cout << ee.get_underlying_bit_size() << '\n'; + std::cout << ee.get_bit_mask() << '\n'; + std::cout << ee.get_unused_bit_mask() << '\n'; return 0; } diff --git a/include/fix8/conjure_enum_bitset.hpp b/include/fix8/conjure_enum_bitset.hpp index 8e721ee..75c4d24 100644 --- a/include/fix8/conjure_enum_bitset.hpp +++ b/include/fix8/conjure_enum_bitset.hpp @@ -71,7 +71,7 @@ class enum_bitset std::conditional_t>>>; static_assert(std::integral, "requested bitset overflow"); - static constexpr U all_bits { (std::size_t{1} << (countof & 63)) - 1 }; + static constexpr U all_bits { (std::size_t{1} << (countof & (sizeof(U) * 8 - 1))) - 1 }; static constexpr U unused_bits { sizeof(U) * 8 - countof }; template @@ -394,9 +394,9 @@ constexpr enum_bitset operator^(const enum_bitset& lh, const enum_bitset struct std::hash> { - size_t operator()(const FIX8::enum_bitset& bs) const noexcept + std::size_t operator()(const FIX8::enum_bitset& bs) const noexcept { - return std::hash::enum_bitset_underlying_type>()(bs.get_underlying()); + return std::hash()(bs.get_underlying()); } }; diff --git a/utests/unittests.cpp b/utests/unittests.cpp index fe60ccd..58b47d7 100644 --- a/utests/unittests.cpp +++ b/utests/unittests.cpp @@ -742,9 +742,9 @@ TEST_CASE("enum_bitset ops") ed.set(); REQUIRE(!ed.has_single_bit()); -#if not defined _MSC_VER +//#if not defined _MSC_VER REQUIRE(std::hash>{}(ed) == 14); -#endif +//#endif } //----------------------------------------------------------------------------------------- From b0ead5cd280948281420077b0f09d6f2c39b2d38 Mon Sep 17 00:00:00 2001 From: David Dight Date: Thu, 12 Sep 2024 07:15:14 +1000 Subject: [PATCH 13/17] pre-rel 1.1.1b --- utests/unittests.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utests/unittests.cpp b/utests/unittests.cpp index 58b47d7..7e5e9d8 100644 --- a/utests/unittests.cpp +++ b/utests/unittests.cpp @@ -742,9 +742,10 @@ TEST_CASE("enum_bitset ops") ed.set(); REQUIRE(!ed.has_single_bit()); -//#if not defined _MSC_VER +#if not defined _MSC_VER REQUIRE(std::hash>{}(ed) == 14); -//#endif +#endif + std::cout << std::hash()(14) << '\n'; } //----------------------------------------------------------------------------------------- From 48abc671cfc5f92594bc4556c0f46fe6c5c98b6d Mon Sep 17 00:00:00 2001 From: David Dight Date: Thu, 12 Sep 2024 07:16:37 +1000 Subject: [PATCH 14/17] pre-rel 1.1.1b --- utests/unittests.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/utests/unittests.cpp b/utests/unittests.cpp index 7e5e9d8..daf4a66 100644 --- a/utests/unittests.cpp +++ b/utests/unittests.cpp @@ -741,11 +741,6 @@ TEST_CASE("enum_bitset ops") REQUIRE(ed.has_single_bit()); ed.set(); REQUIRE(!ed.has_single_bit()); - -#if not defined _MSC_VER - REQUIRE(std::hash>{}(ed) == 14); -#endif - std::cout << std::hash()(14) << '\n'; } //----------------------------------------------------------------------------------------- From 022f3258614755ebad88fada17d38baf54ef4c97 Mon Sep 17 00:00:00 2001 From: David Dight Date: Thu, 12 Sep 2024 07:20:03 +1000 Subject: [PATCH 15/17] pre-rel 1.1.1b --- utests/unittests.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utests/unittests.cpp b/utests/unittests.cpp index daf4a66..cd47404 100644 --- a/utests/unittests.cpp +++ b/utests/unittests.cpp @@ -741,6 +741,8 @@ TEST_CASE("enum_bitset ops") REQUIRE(ed.has_single_bit()); ed.set(); REQUIRE(!ed.has_single_bit()); + + REQUIRE(std::hash>{}(ed) == std::hash::enum_bitset_underlying_type>()(14)); } //----------------------------------------------------------------------------------------- From e0d303cfdb137edeb0ea33ce6a6cf7280cd8c2bf Mon Sep 17 00:00:00 2001 From: David Dight Date: Thu, 12 Sep 2024 07:21:02 +1000 Subject: [PATCH 16/17] pre-rel 1.1.1b --- utests/unittests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utests/unittests.cpp b/utests/unittests.cpp index cd47404..815af1e 100644 --- a/utests/unittests.cpp +++ b/utests/unittests.cpp @@ -742,7 +742,7 @@ TEST_CASE("enum_bitset ops") ed.set(); REQUIRE(!ed.has_single_bit()); - REQUIRE(std::hash>{}(ed) == std::hash::enum_bitset_underlying_type>()(14)); + REQUIRE(std::hash>{}(ed) == std::hash()(14)); } //----------------------------------------------------------------------------------------- From c7ecf3e6eeb47ddce3be122734d7a7b82b8ca30e Mon Sep 17 00:00:00 2001 From: David Dight Date: Thu, 12 Sep 2024 08:37:26 +1000 Subject: [PATCH 17/17] updated --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 86b6c29..3c32ebe 100644 --- a/README.md +++ b/README.md @@ -600,7 +600,7 @@ With a given enum, search and call user supplied invocable. A typical use case w for different enum values. - Where invocable returns a value, return this value or a user supplied "not found" value. -- Where invocable is void, call user supplied "not found" invocable. +- Where invocable is void, call user supplied invocable or "not found" invocable (last in supplied array). The first parameter of your invocable must accept an enum value (passed by `dispatch`). Optionally provide any additional parameters. @@ -2048,7 +2048,7 @@ From a compilation performance perspective, `conjure_enum` roughly matches the p | :--- | :--- | :--- | ---: | | [gcc](https://gcc.gnu.org/projects/cxx-status.html) | `11`, `12`, `13`, `14`| `std::format` not complete in `11`, `12` | `<= 10` | | [clang](https://clang.llvm.org/cxx_status.html) | `15`, `16`, `17`, `18`| Catch2 needs `cxx_std_20` in `15` | `<= 14` | -| [msvc](https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance) | `16`, `17` | Visual Studio 2019,2022, latest `17.11.2`| `<= 16.9`| +| [msvc](https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance) | `16`, `17` | Visual Studio 2019,2022, latest `17.11.3`| `<= 16.9`| | [xcode](https://developer.apple.com/support/xcode/) | `15` | Apple Xcode Clang 15.0.0 (LLVM 16), some issues with `constexpr`, workarounds| `<= 14`| # 11. Compiler issues