Anton Bachin e1e237a4ea Renamed top-level macro ENUM to BETTER_ENUM.
To reduce name clashes.

Fixes #11.
2015-10-04 11:03:08 -05:00
doc Renamed top-level macro ENUM to BETTER_ENUM. 2015-10-04 11:03:08 -05:00
example Renamed top-level macro ENUM to BETTER_ENUM. 2015-10-04 11:03:08 -05:00
extra/better-enums Made N4428 implementation more exact. 2015-07-11 15:25:48 -05:00
script Eliminated underscored internal macro names. 2015-06-05 19:20:18 -05:00
test Renamed top-level macro ENUM to BETTER_ENUM. 2015-10-04 11:03:08 -05:00
.gitignore Switched to CMake for building tests. 2015-07-01 15:18:48 -05:00
.travis.yml Restored clang 3.6 and 3.5 in the Travis build. 2015-07-11 17:29:09 -05:00
appveyor.yml Updated AppVeyor configuration. 2015-08-23 12:38:56 -05:00
enum.h Renamed top-level macro ENUM to BETTER_ENUM. 2015-10-04 11:03:08 -05:00
README.md Renamed top-level macro ENUM to BETTER_ENUM. 2015-10-04 11:03:08 -05:00

Better Enums

Reflective compile-time enum library with clean syntax, in a single header file.

Better Enums code overview

Try online version 0.10.1 BSD license

In C++11, everything can be used at compile time. You can convert your enums, loop over them, find their max, statically enforce conventions, and pass along the results as template arguments or to constexpr functions. All the reflection is available for your metaprogramming needs.

The interface is the same for C++98 — you just have to use most of it at run time only. This library does provide scoped and sized enums, something not built into C++98.

See the project page for full documentation.

Installation

Simply add enum.h to your project — that's it.

Then, include it, and use the BETTER_ENUM macro. Your compiler will generate the rich enums that are missing from standard C++.

Additional features

  • No dependencies and no external build tools. Uses only standard C++, though, for C++98, variadic macro support is required.
  • Supported and tested on clang, gcc, and msvc.
  • Fast compilation. You have to declare a few dozen enums to slow down your compiler as much as just including iostream does.
  • Use any initializers and sparse ranges, just like with a built-in enum.
  • Guaranteed size and alignment — you choose the representation type.
  • Stream operators.
  • Does not use the heap and can be compiled with exceptions disabled, for use in minimal freestanding environments.
  • The underlying type does not have to be an integral type.

Limitations

The biggest limitation is that the BETTER_ENUM macro can't be used inside a class. This seems difficult to remove. There is a workaround with typedef (or C++11 using):

BETTER_ENUM(UniquePrefix_Color, uint8_t, Red, Green, Blue)

struct triplet {
    typedef UniquePrefix_Color      Color;
    Color                           r, g, b;
};

triplet::Color  color;

You can, however, use BETTER_ENUM inside a namespace.

Contact and development

Don't hesitate to contact me about features or bugs: antonbachin@yahoo.com, Twitter @better_enums, or open an issue on GitHub.

If you'd like to help develop Better Enums, see CONTRIBUTING.

master kept stable Travis status AppVeyor status

License and history

Better Enums is released under the BSD 2-clause license. See LICENSE.

The library was originally developed by the author in the winter of 2012-2013 at Hudson River Trading, as a replacement for an older generator called BETTER_ENUM.