How do I use feature-test macros for C++17?

Feature-test macros in C++17 allow developers to check for the availability of specific features and capabilities of the C++ standard library and language. This helps ensure that the code is portable and works across different compiler implementations supporting C++17.
C++17, feature-test macros, C++ standard, compiler support, portability

// Example of using feature-test macros in C++17
#if __cplusplus >= 201703L
#include 
#include 

int main() {
    std::optional opt = 42; // C++17 feature
    if (opt) {
        std::cout << "The value is: " << *opt << std::endl; 
    }
    return 0;
}
#else
#error "This code requires C++17 support."
#endif
    

C++17 feature-test macros C++ standard compiler support portability