AnthonyCalandra / modern-cpp-features

A cheatsheet of modern C++ language and library features.
MIT License
19.6k stars 2.08k forks source link

C++17 __has_include #99

Closed Idclip closed 2 years ago

Idclip commented 3 years ago

__has_include was introduced in C++17. Might be nice to include it (no pun intended): https://en.cppreference.com/w/cpp/preprocessor/include

balaji-ch commented 3 years ago

What is its advantage compared to #include ? How does this compare to import introduced in C++20 ?

AnthonyCalandra commented 3 years ago

@balaji-ch It's a bit different than #include; this just checks for the existence of a header file. cppreference has a good example where you can use __has_include to determine if the compiler has a standard \<optional> header available, or to fallback to an experimental one.

I'm not too familiar with modules yet but I believe import is just the modules version of #include, in other words, does something different than __has_include.

Arsenic-ATG commented 2 years ago

Is this issue still up from grabs ?

If that is so then I am willing to work on it and add necessary documentation about the __has_include operator, along with some examples of the same.

AnthonyCalandra commented 2 years ago

@Arsenic-ATG yes it is, PRs are welcome, just make sure to look at https://github.com/AnthonyCalandra/modern-cpp-features/blob/master/CONTRIBUTING.md#pull-requests first.