-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathenum_bitflags_examples.cpp
49 lines (38 loc) · 1.42 KB
/
enum_bitflags_examples.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
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/enum.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2023, by Matvey Cherevko ([email protected])
******************************************************************************/
#include <enum.hpp/enum_bitflags.hpp>
#include "enum_tests.hpp"
#include <string>
#include <iostream>
namespace
{
enum class perms : unsigned {
execute = 1 << 0,
write = 1 << 1,
read = 1 << 2,
};
ENUM_HPP_OPERATORS_DECL(perms)
}
TEST_CASE("bitflags_examples") {
SUBCASE("Enum operators using") {
namespace bf = enum_hpp::bitflags;
bf::bitflags<perms> flags = perms::read | perms::write;
if ( flags.has(perms::write) ) {
flags.clear(perms::write);
}
flags.set(perms::write | perms::execute);
if ( flags & perms::execute ) {
flags ^= perms::execute; // flags.toggle(perms::execute);
}
CHECK(flags == (perms::read | perms::write));
}
SUBCASE("Additional bitflags functions") {
namespace bf = enum_hpp::bitflags;
bf::bitflags<perms> flags = perms::read | perms::write;
CHECK(bf::any_of(flags, perms::write | perms::execute));
CHECK(bf::any_except(flags, perms::write | perms::execute));
}
}