Skip to content

stlab/enum-ops

Repository files navigation

stlab::enum-ops

CI Documentation License

Type-safe bitmask and arithmetic operators for enum types.

Overview

stlab::enum-ops provides opt-in operator overloads for enum types, enabling:

  • Bitmask operators: ~ | & ^ |= &= ^=
  • Shift operators: << >> <<= >>=
  • Arithmetic operators: + - * / % += -= *= /= and increment/decrement
  • Comparisons with 0 and logical ! for convenience

Opt-in is done by declaring one or both of:

auto stlab_enable_bitmask_enum(E) -> std::true_type;
auto stlab_enable_arithmetic_enum(E) -> std::true_type;

Building & Testing

cmake --preset=test
cmake --build --preset=test
ctest --preset=test

Examples

Examples live under examples/ and are built with the test preset:

cmake --build --preset=test --target enum_ops_example
./build/test/examples/enum_ops_example

Using in your project (CPM)

The simplest way to use stlab::enum-ops in your project is to add it as a dependency via CPM.

CPMAddPackage("gh:stlab/[email protected]")

Documentation

Generate Doxygen docs:

cmake --preset=docs
cmake --build --preset=docs --target docs

License

Distributed under the Boost Software License, Version 1.0. See LICENSE.

About

Typesafe operators for enum types.

Resources

License

Stars

Watchers

Forks

Packages

No packages published