Skip to content

Commit 9d1ce32

Browse files
committed
Merge pull request #2 from grisumbras/development
Turn project into proper library
2 parents 2ca07a0 + db54fd1 commit 9d1ce32

File tree

9 files changed

+835
-372
lines changed

9 files changed

+835
-372
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
*.exe
2020
*.out
2121
*.app
22+
23+
# Test artefacts
24+
test/bin

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The only drawback to type safety is you cannot treat variables of *enum class*
1010
types as sets of flags. That is because *enum classes* do not cast to integers
1111
and there are no bitwise operators overloads defined for them.
1212

13-
This project brings a `flags` class template which:
13+
This library brings a `flags` class template which:
1414
* does not convert to or from integer types;
1515
* does implicitly convert from enum it was instantiated by;
1616
* does not convert to that enum;
@@ -19,24 +19,31 @@ This project brings a `flags` class template which:
1919
* explicitly converts to bool (which allows to use it in boolean contexts, like
2020
in branching or loop conditions);
2121
* provides access to the underlying integer through member functions;
22-
* instantiates only for enum classes.
22+
* instantiates only for enums it was explicitly enabled for.
2323

2424
## Usage
2525
``` c++
2626
enum class MyEnum { Value1 = 1 << 0, Value2 = 1 << 1 };
27-
using MyEnums = flags<MyEnum>; // actually this line is not necessary
2827

29-
auto mask = Value1 | Value2; // set flags Value1 and Value 2
30-
if (mask & Value2) { // if Value2 flag is set
31-
doSomething();
28+
namespace flags {
29+
template <> struct is_flags<MyEnum> : std::true_type {};
30+
}
31+
// or just use macro:
32+
// ALLOW_FLAGS_FOR_ENUM(MyEnum)
33+
34+
using MyEnums = flags::flags<MyEnum>;
35+
36+
MyEnums mask1 = Value1 | Value2; // set flags Value1 and Value 2
37+
if (mask1 & Value2) { // if Value2 flag is set
38+
doSomething();
3239
}
3340
```
3441
3542
## Description
3643
``` c++
3744
template <class E> class flags;
3845
```
39-
where `E` is an enum class.
46+
where `E` is an enum.
4047

4148
### Member types
4249
Member type |Definition |Notes

0 commit comments

Comments
 (0)