Is there a standard definition for __cplusplus in c++14?

__cplusplus

denotes the version of C++ standard that is being used, expands to value 199711L(until C++11), 201103L(C++11), 201402L(C++14), 201703L(C++17), or 202002L(C++20)
(macro constant)
https://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros
I am going to start putting this into code that requires it, beginners are always asking why code doesn't compile, because they don't use the right standard.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
// #if __cplusplus < 201103L 
// #error "C++11 or better required\n"
// #endif
// #if __cplusplus < 201402L 
// #error "C++14 or better required\n"
// #endif

#if __cplusplus < 201703L 
#error "C++17 or better required\n"
#endif

// #if __cplusplus < 202002L 
// #error "C++20 or better required\n"
// #endif 


Edit:

I also like these from c++20, will put them in code, but only for those where support is missing or partial from one of g++, clang++ , Apple clang or MSVC. For example __cpp_modules

https://en.cppreference.com/w/cpp/feature_test
Last edited on
Also, be wary of how your compiler treats the option to specify C++14.

For example, on gnu and clang, you'll need to specify -pedantic to stop it from automatically pulling in newer features.
why does OP have a link to walgreens?
Looks like a low quality spam of some sort.
Topic archived. No new replies allowed.