Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.


Artifact ID: 1642ff4e434f6fa7d63b8b52c3c21b2b030c8a06
Page Name:BehaviourMacros
Date: 2017-08-11 17:40:15
Original User: luismachuca
Parent: 01537d87a6fc3da7195c0e62988a3deabacc5ba4

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 example 2011 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 format 100*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

== 1

Emits basic library identification messages.
Emits standard vs emulation notice.
Emits a message when an "Extra" feature is included.
== 2Emits compiler identification messages related to patches.
Emits notification when additions to TR1 library headers (<functional>, <tuple>, etc...) are included.
== 3Emits 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:


Nonzero if...
CXXO_COMPILER_SUPPORT_attribute[[attribute]] is supported
CXXO_COMPILER_SUPPORT_autoC++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_deleteC++11 "=default" and "=delete" for members is supported
CXXO_COMPILER_SUPPORT_foreachC++11 'for(i: range)' syntax is supported
CXXO_COMPILER_SUPPORT_local_typesC++11 locally defined types as arguments for templates is supported
CXXO_COMPILER_SUPPORT_noexceptC++11 'noexcept' is supported
CXXO_COMPILER_SUPPORT_rvrefC++11 rvalue-references (T&&) is supported
CXXO_COMPILER_SUPPORT_variadicC++11 variadic template arguments is supported

The library also provides the ability to write conditional code depending on the detected C++ version: