summaryrefslogtreecommitdiffhomepage
path: root/compat/enum-bitset.hpp
blob: 1365b3fbdb75499dd3b881b5e7902e452f909468 (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>
requires std::is_enum_v<Enum>
struct enum_bitset : std::bitset<(std::size_t)Enum::MAX> {
    using type = Enum;
    static_assert(std::is_same_v<std::size_t, std::common_type_t<std::size_t, std::underlying_type_t<Enum>>>);
    static_assert(std::is_same_v<Enum, std::decay_t<Enum>>);
    using std::bitset<(std::size_t)Enum::MAX>::bitset;
    constexpr bool operator[](Enum x) const { return operator[]((std::size_t)x); }
    constexpr decltype(auto) operator[](Enum x) {
        return std::bitset<(std::size_t)Enum::MAX>::operator[]((std::size_t)x);
    }
};

} // namespace floormat