Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check for C++11 support?

Tags:

c++

c++11

Is there a way to detect at compile-time if the compiler supports certain features of C++11? For example, something like this:

#ifndef VARIADIC_TEMPLATES_SUPPORTED  #error "Your compiler doesn't support variadic templates.  :("  #else  template <typename... DatatypeList> class Tuple {     // ... }  #endif 
like image 512
Maxpm Avatar asked Feb 19 '11 00:02

Maxpm


People also ask

What version of gcc supports C ++ 11?

Status of Experimental C++11 Support in GCC 4.8 GCC provides experimental support for the 2011 ISO C++ standard. This support can be enabled with the -std=c++11 or -std=gnu++11 compiler options; the former disables GNU extensions.

Does Visual Studio support C11?

Support for C11 and C17 standards is available in Visual Studio 2019 version 16.8 and later.

How do I know what version of C compiler I have?

Type “gcc –version” in command prompt to check whether C compiler is installed in your machine.


1 Answers

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.

like image 73
Cygon Avatar answered Oct 19 '22 23:10

Cygon