Easily Find Feature Test Macros with the <version> Header

Learn to find feature test macros with the <version> header.

We'll cover the following

C++ has provided some form of feature test macros for as long as new features have been added. Beginning with C++20, the process is standardized, and all library feature test macros have been added to the <version> header. This will make it much easier to test for a new feature in our code.

This is a useful feature and it's very simple to use.

How to do it

All feature test macros begin with the prefix __cpp_. Library features begin with __cpp_lib_. Language feature test macros are typically defined by the compiler. Library feature test macros are defined in the new <version> header. Use them as we would any other preprocessor macro:

Get hands-on with 1200+ tech skills courses.