-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathmain.cpp
60 lines (49 loc) · 1.16 KB
/
main.cpp
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 "bec/bitfield-enum-class.hpp"
#include <iostream>
enum class Key
{
None = 0,
Red = 1 << 0,
Green = 1 << 1,
Blue = 1 << 2,
Purple = 1 << 3,
Yellow = 1 << 4,
Orange = 1 << 5,
};
template<>
struct bec::EnableBitMaskOperators<Key>
{
static const bool Enable = true;
};
enum class Team
{
None = 0,
Green = 1 << 0,
Purple = 1 << 1,
Orange = 1 << 2,
Yellow = 1 << 3,
Red = 1 << 4,
Blue = 1 << 5,
};
template<>
struct bec::EnableBitMaskOperators<Team>
{
static const bool Enable = true;
};
// simple example program using bitfield-enum-class library
int main(int argc, char** argv) {
using bec::operator&;
using bec::operator|;
using bec::operator|=;
Key collected_keys = Key::None;
collected_keys |= Key::Red | Key::Green;
if ((collected_keys & Key::Red) == Key::Red) {
std::cout << "Collected the Red key\n";
}
Team participating_teams = Team::None;
participating_teams |= Team::Blue | Team::Purple;
if ((participating_teams & Team::Blue) == Team::Blue) {
std::cout << "Blue team is participating\n";
}
return 0;
}