-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitnum-test.cpp
More file actions
60 lines (42 loc) · 936 Bytes
/
bitnum-test.cpp
File metadata and controls
60 lines (42 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "bitnum/bitset_enum_cpp17.h"
#include <assert.h>
namespace Test
{
enum class ETest
{
Left = 1,
Right = 2,
Middle = 4,
};
void enable_bitset_enum(ETest);
}
#pragma warning(disable:26813) // "use & to test if a flag is set in bitwise enums"
int main()
{
using namespace Test;
{
constexpr auto x = ETest::Left | ETest::Right;
static_assert(std::is_same_v<decltype(x), const ETest>);
static_assert((int)x == 3);
}
{
auto x = ETest::Left | ETest::Right;
assert((int) x == 3);
x |= ETest::Middle;
assert((int)x == 7);
x -= ETest::Right;
assert((int)x == 5);
x &= ETest::Left;
assert((int)x == 1);
}
{
auto x = ETest::Left | ETest::Right;
assert((int)x == 3);
auto y = x | ETest::Middle;
assert((int)y == 7);
auto z = y - ETest::Right;
assert((int)z == 5);
auto _ = z & ETest::Left;
assert((int)_ == 1);
}
}