__has_include Preprocessor Expression
Explore how to use C++17's __has_include preprocessor expression to detect header file availability, enabling you to write adaptable code for multiple compilers and handle feature differences effectively.
We'll cover the following...
We'll cover the following...
__has_include
If your code has to work under two different compilers, then you might experience two different sets of available features and platform-specific changes.
In C++17 you can use __has_include preprocessor constant expression to check if a given header exists:
#if __has_include(<header_name>)
#if __has_include("header_name")
__has_include was available in Clang as an extension for many years, but now it was added to the Standard. It’s a part of “feature testing” helpers that allows you to check if a particular ...