Compiler support - Better Enums (original) (raw)
Compiler support
Better Enums aims to support all major compilers. It is known to work on:
- clang 3.3 to 3.9
- gcc 4.3 to 5.3
- Visual C++ 2008 to 2015.
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:
- you want to use Better Enums reflection at compile time, and need to know exactly what features are supported on your compiler, or
- Better Enums is choosing the wrong configuration automatically and you need to force a different choice.
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:
- C++98
- fast
constexpr - full
constexpr
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:
- First, as of the time of this writing, only clang and gcc support
constexpr. So, if you are using any other compiler, Better Enums is inC++98 mode. - If you are using gcc 4.7 or higher or clang, Better Enums uses those compilers' predefined macros to detect whether
constexprsupport is enabled with compiler flags. If so, it is in one of theconstexprmode. Otherwise, it falls back to C++98 mode. - The default
constexprmode is fastconstexpr. If you want to enable fullconstexprmode for some or all of your enums, followthese instructions.
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.