__cplusplus should be defined as 199711L in pre-C ++ 11, 201103L in those who support C ++ 11. In practice, this is another question: most compilers are only halfway, so you should not define it as 201103L , even if they support features that interest you. And this is not unheard of for the compiler for lie: a compiler that defines it as 199711L and does not support export for templates, for example. But a functional check does not exist.
The simplest solution is to simply not use any specific new function until you are sure that all its compilers support it. You should still write and maintain backup code; why support two versions. The only exception to this rule may be new features that affect performance: whether the compiler supports transfer semantics or not. In such cases, I would suggest including a compiler dependent file that you write based on compiler documentation and personal tests; simply because the compiler can document that it supports a particular function does not mean that its support is not an error. Just create a directory for each target compiler, put this file there and specify the appropriate -I or /I option in the makefile or project file.
And your tests should be something like:
#ifdef HAS_MOVE_SEMANTICS ... #endif
not just the compiler, version, or something else.
James Kanze May 23 '12 at 10:04 a.m. 2012-05-23 10:04
source share