"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How Can I Check for C++11 Compiler Support?

How Can I Check for C++11 Compiler Support?

Posted on 2025-02-06
Browse:440

How Can I Check for C  11 Compiler Support?

Checking for C 11 Support

In C , determining if a compiler supports specific features of C 11 is crucial for ensuring compatibility. Some methods exist to perform this check at compile-time, including:

Using __cplusplus Constant

The __cplusplus constant, defined by the preprocessor, indicates the supported C standard version. For example:

#if __cplusplus 

Using Boost Defines

Boost provides defines (__has_feature(feature_name)) that enable checking for specific C 11 features, such as:

#if __has_feature(cxx_automatic_resource_management)
  // C  11 has automatic resource management
#endif

Example: Checking for Variadic Templates

Suppose you want to use variadic templates, a C 11 feature. You can check for its support using the following code:

#ifndef VARIADIC_TEMPLATES_SUPPORTED

#error "Your compiler doesn't support variadic templates.  :("

#else

template 
class Tuple
{
    // ...
}

#endif
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3