You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`__has_include (operand)` operator may be used in `#if` and `#elif` expressions to check whether a header or source file (`operand`) is available for inclusion or not.
316
+
317
+
One use case of this would be using two libraries that work the same way, using the backup/experimental one if the preferred one is not found on the system.
318
+
319
+
```c++
320
+
#ifdef __has_include
321
+
# if __has_include(<optional>)
322
+
# include <optional>
323
+
# define have_optional 1
324
+
# elif __has_include(<experimental/optional>)
325
+
# include <experimental/optional>
326
+
# define have_optional 1
327
+
# define experimental_optional
328
+
# else
329
+
# define have_optional 0
330
+
# endif
331
+
#endif
332
+
```
333
+
334
+
It can also be used to include headers existing under different names or locations on various platforms, without knowing which platform the program is running on, OpenGL headers are a good example for this which are located in `OpenGL\` directory on macOS and `GL\` on other platforms.
`__has_include (operand)` operator may be used in `#if` and `#elif` expressions to check whether a header or source file (`operand`) is available for inclusion or not.
967
+
968
+
One use case of this would be using two libraries that work the same way, using the backup/experimental one if the preferred one is not found on the system.
969
+
970
+
```c++
971
+
#ifdef __has_include
972
+
# if __has_include(<optional>)
973
+
# include <optional>
974
+
# define have_optional 1
975
+
# elif __has_include(<experimental/optional>)
976
+
# include <experimental/optional>
977
+
# define have_optional 1
978
+
# define experimental_optional
979
+
# else
980
+
# define have_optional 0
981
+
# endif
982
+
#endif
983
+
```
984
+
985
+
It can also be used to include headers existing under different names or locations on various platforms, without knowing which platform the program is running on, OpenGL headers are a good example for this which are located in `OpenGL\` directory on macOS and `GL\` on other platforms.
0 commit comments