An open API service indexing awesome lists of open source software.

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

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/)