How do I check for presence of individual C++0x/C++11 language features? I know Clang has a nice system for this. What about GCC, Visual Studio or Boost? I guess one way to do it is to detect the compiler version and relate that to the features introduced in that version. But that is cumbersome. Has someone already done that?
-
1Straight forward answer would be to write a code with that feature and compile it. – iammilind Apr 19 '12 at 09:58
-
Why should this question be closed? – Nordlöw Apr 19 '12 at 10:15
-
@Nordlöw : Two people voted to close it as a duplicate of [this question](http://stackoverflow.com/q/6095885/636019). – ildjarn Apr 19 '12 at 17:26
2 Answers
boost config comes with a script to check for some but not all C++11 features.
It generates a config-file with macros for each feature.
-
I think you meant to write something after *See:*. Anyway, yes Boost.Config is probably the best bet. The Boost guys already track down that information so that one does not have to: they bug compiler's team to know precisely when it was stable enough to be advertised, or in the case of Clang request new check flags. – Matthieu M. Apr 19 '12 at 10:28
-
Actually it was a leftover from a draft-answer. I will delete it. Thanks. – mirk Apr 19 '12 at 10:31
Your build-tool may be able to help with this.
CMake has the try_compile
command which allows you to test whether a code sample will compile and set a variable based on the result of compilation.
At the moment I've just been using the more commonly supported features such as auto
typing.
You can often use Boost to replace the missing library features, and this may be the best option for a few year while compilers and libraries are updated and bugs fixed.
The C++11 feature compatibility list for GCC is here: http://gcc.gnu.org/projects/cxx0x.html
Note the warning:
Important: GCC's support for C++11 is still experimental. Some features were implemented based on early proposals, and no attempt will be made to maintain backward compatibility when they are updated to match the final C++11 standard.

- 8,017
- 1
- 28
- 43