summaryrefslogtreecommitdiffhomepage
path: root/compat/enum-bitset.hpp
blob: ebbd9982523e22e406d6ca44f24f4b12b534d20a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#pragma once
#include <bitset>

namespace floormat {

template<typename Enum, Enum COUNT_ = Enum::COUNT>
requires (std::is_enum_v<Enum> && std::is_same_v<size_t, std::common_type_t<size_t, std::underlying_type_t<Enum>>>)
struct enum_bitset : std::bitset<size_t(COUNT_)> {
    using enum_type = Enum;
    using value_type = std::underlying_type_t<enum_type>;

    static constexpr auto COUNT = size_t{value_type(COUNT_)};

    using std::bitset<COUNT>::bitset;
    constexpr bool operator[](Enum x) const { return std::bitset<COUNT>::operator[](size_t{value_type(x)}); }
    constexpr decltype(auto) operator[](Enum x) { return std::bitset<COUNT>::operator[](size_t{value_type(x)}); }
};

} // namespace floormat