Better Enums is a single header file that causes your compiler to generate *reflective* enum types. This makes it easy to translate between enums and strings, and much more. Here's how to use a Better Enum:
enable declare parse print count iterate switch safe cast at compile time
#include <enum.h>
ENUM(Channel, int, Red = 1, Green, Blue)
Channel c = Channel::_from_string("Red");
const char *s = c._to_string();
size_t n = Channel::_size;
for (Channel c : Channel::_values())
run_some_function(c);
switch (c) {
case Channel::Red: // ...
case Channel::Green: // ...
case Channel::Blue: // ...
}
Channel c = Channel::_from_integral(3);
constexpr Channel c = Channel::_from_string("Blue");
constexpr functions.
switch
Use a Better Enum like a built-in enum, and still have the
compiler do case checking.
enums. Generated members have underscores to avoid conflicts
with your constant names.
switch statements for
converting enums to strings.
enum.h. It's a metaprogram executed by your
compiler.
iostream.
enum.h.
enum.h
Current version: $version