Basic Macros
When this library is included in a piece of software, the following macros are defined:
CXXOMFORT_DATE
- it expands to an unsigned integer representing the release date of the current version in the format YYYYMM.CXXOMFORT_CXX_STD
- resolves to a numeric value indicating the Standard version supported by the compiler, for example2011
for C++11-compliant compilers.CXXOMFORT_CXX_EMULATION
- resolves to a numeric value that corresponds the Standard version that the compiler is emulating, if it is operating in an "emulation" mode such as GCC's c++0x.CXXOMFORT_COMPILER_ID
- this expands to a numerical code identifying the compiler, if it has been identified.CXXOMFORT_COMPILER_VERSION
- this expands to a numerical code identifying the compiler version, using the format100*major+minor
where possible.
The following macros exist and deliver information but are to be deprecated in a future version:
CXXOMFORT_VERSION
- it expands to an unsigned integer representing the library version with the formula 100*major+minor.
Configuration Macros
The behaviour of this library can be queried or configured via a set of macros.
The following macros can be used to change the behaviour of this library:
CXXOMFORT_NOTICES
- if defined and nonzero, the library will emit some diagnostics indicating what features are being used, etc. These diagnostics do not affect the code being compiled and are only informative. The higher the value of the macro, the more diagnostics does the library emit.CXXOMFORT_NO_TR1
- if defined, the library will not#include
some of the headers required for TR1 features. Note that this configuration is not supported, after all part of the purpose of this library is to make those features usable.
Diagnostics emitted by CXXOMFORT_NOTICES
| Emits basic library identification messages. Emits standard vs emulation notice. Emits a message when an "Extra" feature is included. |
== 2 | Emits compiler identification messages related to patches. Emits notification when additions to TR1 library headers (<functional>, <tuple>, etc...) are included. |
== 3 | Emits notifications of all features being included.Emits patching diagnostics. |
"Standard Mode" and "Emulation Mode"
This library attempts to detect when the compiler supports the C++98/03, C++11 or C++14 Standard and is using its features, in which case it sets the value of the macro CXXOMFORT_CXX_STD
to the given year (1998, 2011 or 2014) for use.
Identification of C++11 Mode relies in the Standard-specified method of announcing compliance - that is, by defining the identifier __cplusplus
to an adequate value.
In some environments, the library can also detect if the compiler is operating in a C++11 or C++14 "emulation" mode, usually called "C++0x", "c++1y" or the like, where only a subset of features is implemented and/or they are done only partially. If such emulation mode is detected, the macro CXXOMFORT_CXX_EMULATION
takes the value of the given year of the standard emulated.
Identification of Emulation Mode is a compiler-dependent and project-dependent feature, so this method is not exact. For a compiler to be recognized as operating in C++11 mode, for example, the following need to hapen:
- The compiler advertises C++11 emulation mode by defining a particular macro (for example
GNUXX_EXPERIMENTAL_CXX0X
in GCC).
Values of the control macros under different settings:
Build Setup | Compiler and Version | CXX_STD | CXX_EMULATION |
---|---|---|---|
GCC 4.6, --std=c++03 | 101 0406 | 1997 | 0 |
GCC 4.6, --std=c++0x | 101 0406 | 1997 | 2011 |
GCC 4.4, no --std flag | 101 0404 | 1997 | 0 |
GCC 4.4, --std=c++0x | 101 0404 | 1997 | 2011 |
GCC 4.8, --std=c++03 | 101 0408 | 1997 | 0 |
GCC 4.8, --std=c++11 | 101 0408 | 2011 | 2011 |
MSVC 2010 | 103 0160 | 1997 | 2011 |
MSVC 2008 SP1 | 103 0150 | 1997 | 0 |
MSVC 2015 C++ Build Tools | N/A | ||
Clang 3.4, --std=c++03 | 104 0304 | 1997 | 0 |
Clang 3.4, --std=c++11 | 104 0304 | 2011 | 0 |
Clang 3.2 | N/A | ||
Open Watcom | N/A | ||
The library also sets a number of macros to determine what features are found as supported by the compiler in either Standard or Emulation mode:
Macro | Nonzero if... |
---|---|
CXXO_COMPILER_SUPPORT_attribute | [[attribute]] is supported |
CXXO_COMPILER_SUPPORT_auto | C++11 type-deducing semantics for 'auto' is supported |
CXXO_COMPILER_SUPPORT_constexpr | 'constexpr' is supported |
CXXO_COMPILER_SUPPORT_decltype | 'decltype' is supported |
CXXO_COMPILER_SUPPORT_default_delete | C++11 "=default" and "=delete" for members is supported |
CXXO_COMPILER_SUPPORT_foreach | C++11 'for(i: range)' syntax is supported |
CXXO_COMPILER_SUPPORT_local_types | C++11 locally defined types as arguments for templates is supported |
CXXO_COMPILER_SUPPORT_noexcept | C++11 'noexcept' is supported |
CXXO_COMPILER_SUPPORT_rvref | C++11 rvalue-references (T&&) is supported |
CXXO_COMPILER_SUPPORT_variadic | C++11 variadic template arguments is supported |
The library also provides the ability to write conditional code depending on the detected C++ version:
CXXOMFORT_CXX11_CODE(cxx11,cxx03)
- this macro allows to write small snippets of code, such as keywords, conditioned to operating in C++11 onwards or C++03 mode.CXXOMFORT_CXX14_CODE(cxx14,cxx01)
- this macro allows to write small snippets of code, such as keywords, conditioned to operating in C++14 onwards or C++11 backwards mode.