How do I check for C++11 support?

There is a constant named __cplusplus that C++ compilers should set to the version of the C++ standard supported see this

#if __cplusplus <= 199711L
  #error This library needs at least a C++11 compliant compiler
#endif

It is set to 199711L in Visual Studio 2010 SP1, but I do not know if vendors will be so bold to increase it already if they just have (partial) compiler-level support versus a standard C++ library with all the C++11 changes.

So Boost's defines mentioned in another answer remain the only sane way to figure out if there is, for example, support for C++11 threads and other specific parts of the standard.


As stated by the C++11 standard (§iso.16.8):

The name __cplusplus is defined to the value 201103L when compiling a C++ translation unit.

With the value of that macro, you can check whether the compiler is C++11 compliant.

Now, if you are looking for a standard way to check if the compiler supports a whatsoever subset of C++11 features, I think there is no standard, portable way; you can check compilers documentation or std library header files to get more information.


I know that this is a very old question, but this question might be often seen, and the answers are a bit out of date.

Newer compilers with the C++14 standard have a standard way to check features, including C++11 features. A comprehensive page is at https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations

In summary, each feature has a standard macro defined that you can check with #ifdef. For example, to check for user defined literals, you can use

#ifdef __cpp_user_defined_literals

Tags:

C++

C++11