From 1bf360c037aed5fc854cf1fcacaa65894422e0f0 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Tue, 5 Oct 2021 10:56:58 -0400 Subject: [PATCH] Include if possible to check if we can use the feature Addresses #303 --- include/cxxopts.hpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index af87540..8fe2646 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -51,9 +51,14 @@ THE SOFTWARE. # include #endif // CXXOPTS_NO_REGEX -#ifdef __cpp_lib_optional -#include -#define CXXOPTS_HAS_OPTIONAL +// Nonstandard before C++17, which is coincidentally what we also need for +#ifdef __has_include +# if __has_include() +# include +# ifdef __cpp_lib_optional +# define CXXOPTS_HAS_OPTIONAL +# endif +# endif #endif #if __cplusplus >= 201603L @@ -1355,7 +1360,7 @@ namespace cxxopts { return m_count; } - + #if defined(CXXOPTS_NULL_DEREF_IGNORE) #pragma GCC diagnostic pop #endif