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 __cplusplusUsing 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 #endifExample: 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 templateclass Tuple { // ... } #endif
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