LeviLamina
Loading...
Searching...
No Matches
EnumSet.h
1
#pragma once
2
3
#include "mc/_HeaderOutputPredefine.h"
4
#include "mc/platform/brstd/bitset.h"
5
6
namespace
Bedrock {
7
8
template
<
typename
TEnum, auto SizeEnum>
9
class
EnumSet
{
10
public
:
11
using
size_type = size_t;
12
static
constexpr
size_type MaxSize =
static_cast<
size_type
>
(SizeEnum);
13
using
mContainertype =
brstd::bitset<MaxSize, std::underlying_type_t<TEnum>
>;
14
using
value_type = TEnum;
15
16
mContainertype mContainer;
17
18
class
iterator {
19
using
reference = TEnum;
20
21
public
:
22
friend
class
EnumSet;
23
iterator(EnumSet
const
& set, size_type index) : set_(&set), index_(index) {}
24
EnumSet
const
* set_;
25
size_type index_;
26
};
27
static_assert
(
sizeof
(
iterator
) == 16);
28
29
using
const_iterator =
iterator
;
30
31
constexpr
std::pair<iterator, bool> insert(value_type value) {
32
using
U = std::underlying_type_t<TEnum>;
33
auto
idx =
static_cast<
U
>
(value);
34
if
(mContainer.test(idx)) {
35
return
{
iterator
(*
this
, idx),
false
};
36
}
37
mContainer.set(idx);
38
return
{iterator(*
this
, idx),
true
};
39
}
40
41
constexpr
bool
contains(value_type
const
value)
const
{
42
using
U = std::underlying_type_t<TEnum>;
43
return
mContainer.test(
static_cast<
U
>
(value));
44
}
45
};
46
47
}
// namespace Bedrock
Bedrock::EnumSet::iterator
Definition
EnumSet.h:18
Bedrock::EnumSet
Definition
EnumSet.h:9
brstd::bitset
Definition
bitset.h:19
src
mc
deps
core
container
EnumSet.h
Generated on
for LeviLamina by
1.16.1