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 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 fc1f9dc..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 { (1 << countof) - 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 @@ -116,7 +116,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)) {} @@ -143,9 +143,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; } @@ -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 278794f..815af1e 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, @@ -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)); } @@ -742,7 +742,7 @@ TEST_CASE("enum_bitset ops") ed.set(); REQUIRE(!ed.has_single_bit()); - REQUIRE(std::hash>{}(ed) == 14); + REQUIRE(std::hash>{}(ed) == std::hash()(14)); } //-----------------------------------------------------------------------------------------