Macro __cplusplus
Macro __cplusplus
Macro __cplusplus
Use Case: Check Compiler Setting Check Compiler Setting
#ifndef __cplusplus
#error C++ is required
#elif __cplusplus > 199711L
// C++11 (or newer) code goes here
#else
// old-school code goes here
#endif
Standard Values
C++98 | #define __cplusplus |
C++03 | #define __cplusplus |
C++11 | #define __cplusplus |
C++14 | #define __cplusplus |
C++17 | #define __cplusplus |
C++20 | #define __cplusplus |
Older Compilers
If a compiler was released between C++ standards,
values for __cplusplus
might differ
from the ones in the above table.
However, you can always rely on the fact that
the value of __cplusplus
for a newer standard
will be strictly larger than that of the previous standard.