https://github.com/curve/flagpp
🏴☠️ (Opt-In) Bitwise operations on scoped enums
https://github.com/curve/flagpp
Last synced: 8 months ago
JSON representation
🏴☠️ (Opt-In) Bitwise operations on scoped enums
- Host: GitHub
- URL: https://github.com/curve/flagpp
- Owner: Curve
- License: mit
- Created: 2023-06-13T21:37:37.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-07-31T14:15:06.000Z (almost 2 years ago)
- Last Synced: 2024-08-01T17:54:51.928Z (almost 2 years ago)
- Language: C++
- Size: 36.1 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A C++23 library that provides (opt-in) bit-wise operations for arbitrary `enum class`es
## 📦 Installation
> [!NOTE]
> See versions `< 3.0` for C++20 support!
* Using [CPM](https://github.com/cpm-cmake/CPM.cmake)
```cmake
CPMFindPackage(
NAME flagpp
VERSION 3.0
GIT_REPOSITORY "https://github.com/Curve/flagpp"
)
```
* Using FetchContent
```cmake
include(FetchContent)
FetchContent_Declare(flagpp GIT_REPOSITORY "https://github.com/Curve/flagpp" GIT_TAG v3.0)
FetchContent_MakeAvailable(flagpp)
target_link_libraries( flagpp)
```
## 📃 Usage
```cpp
#include
enum class my_enum
{
none,
a = 1 << 0,
b = 1 << 1,
c = 1 << 2,
};
template <>
constexpr bool flagpp::enabled = true;
// You can now use `my_enum` for bit-wise operations!
auto flag = my_enum::a;
flag |= my_enum::b;
flag |= my_enum::c;
if (flag & my_enum::b)
{
flag &= ~my_enum::b;
}
```
> For more examples see [tests](tests/)