Commit 4a02ad94f42841fc718bbcf128e0b674b336a074

Authored by Nick Krichevsky
Committed by GitHub
1 parent c641241a

Include <optional> if possible to check if we can use the feature (#309)

Fixes #303
Showing 1 changed file with 9 additions and 4 deletions
include/cxxopts.hpp
... ... @@ -51,9 +51,14 @@ THE SOFTWARE.
51 51 # include <regex>
52 52 #endif // CXXOPTS_NO_REGEX
53 53  
54   -#ifdef __cpp_lib_optional
55   -#include <optional>
56   -#define CXXOPTS_HAS_OPTIONAL
  54 +// Nonstandard before C++17, which is coincidentally what we also need for <optional>
  55 +#ifdef __has_include
  56 +# if __has_include(<optional>)
  57 +# include <optional>
  58 +# ifdef __cpp_lib_optional
  59 +# define CXXOPTS_HAS_OPTIONAL
  60 +# endif
  61 +# endif
57 62 #endif
58 63  
59 64 #if __cplusplus >= 201603L
... ... @@ -1361,7 +1366,7 @@ namespace cxxopts
1361 1366 {
1362 1367 return m_count;
1363 1368 }
1364   -
  1369 +
1365 1370 #if defined(CXXOPTS_NULL_DEREF_IGNORE)
1366 1371 #pragma GCC diagnostic pop
1367 1372 #endif
... ...