Compiler support - Better Enums (original) (raw)

Compiler support

Better Enums aims to support all major compilers. It is known to work on:

The library can be used with any compiler that supports either C++11, or C++98with the __VA_ARGS__ extension. This includes every version of gcc and clang I have ever heard of, and Visual C++ down to 2005.

To ensure that nothing is broken, every release of Better Enums istested in multiple configuratins on the compilers listed above. Testing includes the code in the tutorials, the unit tests, and a multiple translation unit linking test. The full list of tested compilers and configurations is given at the end of this page.

Compile-time reflection configurations

Read this section if:

All features of Better Enums are always available for run-time use. However, for compile-time use, Better Enums has two main configurations: C++98 mode andconstexpr mode. Better Enums tries to detect which compiler is compiling it and select the appropriate mode.

For performance reasons, constexpr mode is subdivided into a "fast"constexpr mode and anopt-in "full" (slow)constexpr mode. The three modes can be ranked, with each next mode including all the features of the preceding ones:

Only _size is supported at compile time in C++98 mode. Fast constexpr mode adds all other members besides _to_string and _names. Full constexpr mode supports those at compile time as well.


The mode selection code works as follows:

If Better Enums picks the wrong mode, you can force constexpr mode by definingBETTER_ENUMS_CONSTEXPR before including enum.h, typically by passing an option to your compiler, or you can force C++98 mode by definingBETTER_ENUMS_NO_CONSTEXPR.

If you are using a compiler for which Better Enums makes the wrong choice, please let me know. I will fix it and you won't have to define these macros anymore.

Tested configurations