Skip to content

Commit

Permalink
Merge pull request #18 from fix8mt/dev
Browse files Browse the repository at this point in the history
Dev to Master: windows bitset fix
  • Loading branch information
dakka authored Sep 11, 2024
2 parents f7b22f4 + c7ecf3e commit 0198333
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions examples/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,12 @@ int main(void)
for (const auto& [ev,str] : {en::front(), en::back()})
std::cout << static_cast<int>(ev) << ' ' << str << '\n';

enum_bitset<numbers> 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;
}
12 changes: 6 additions & 6 deletions include/fix8/conjure_enum_bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class enum_bitset
std::conditional_t<countof <= 64, std::uint_least64_t, void>>>>;
static_assert(std::integral<U>, "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 <typename R>
Expand Down Expand Up @@ -116,7 +116,7 @@ class enum_bitset
using const_reference = _reference<const enum_bitset>;

explicit constexpr enum_bitset(U bits) noexcept : _present(bits) {}
explicit constexpr enum_bitset(std::bitset<countof> from) : _present(from.to_ullong()) {}
explicit constexpr enum_bitset(std::bitset<countof> 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)) {}

Expand All @@ -143,9 +143,9 @@ class enum_bitset
{
if (std::bit_width<U>(_present) > 32)
throw std::overflow_error("overflow");
return _present;
return static_cast<unsigned long>(_present);
}
constexpr unsigned long long to_ullong() const noexcept { return _present; }
constexpr unsigned long long to_ullong() const noexcept { return static_cast<unsigned long long>(_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; }
Expand Down Expand Up @@ -394,9 +394,9 @@ constexpr enum_bitset<T> operator^(const enum_bitset<T>& lh, const enum_bitset<T
template<typename T>
struct std::hash<FIX8::enum_bitset<T>>
{
size_t operator()(const FIX8::enum_bitset<T>& bs) const noexcept
std::size_t operator()(const FIX8::enum_bitset<T>& bs) const noexcept
{
return std::hash<typename FIX8::enum_bitset<T>::enum_bitset_underlying_type>()(bs.get_underlying());
return std::hash<std::size_t>()(bs.get_underlying());
}
};

Expand Down
6 changes: 3 additions & 3 deletions utests/unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -691,7 +691,7 @@ TEST_CASE("enum_bitset <==> std::bitset")
std::bitset<10> bs{1 << 1 | 1 << 3 | 1 << 6};
enum_bitset<numbers> 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));
}

Expand Down Expand Up @@ -742,7 +742,7 @@ TEST_CASE("enum_bitset ops")
ed.set<numbers::one,numbers::three>();
REQUIRE(!ed.has_single_bit());

REQUIRE(std::hash<enum_bitset<numbers>>{}(ed) == 14);
REQUIRE(std::hash<enum_bitset<numbers>>{}(ed) == std::hash<std::size_t>()(14));
}

//-----------------------------------------------------------------------------------------
Expand Down

0 comments on commit 0198333

Please sign in to comment.