diff --git a/include/boost/container_hash/hash/hash.hpp b/include/boost/container_hash/hash/hash.hpp index f7cd21d..41cab8a 100644 --- a/include/boost/container_hash/hash/hash.hpp +++ b/include/boost/container_hash/hash/hash.hpp @@ -62,21 +62,28 @@ # define BOOST_FUNCTIONAL_HASH_ROTL32(x, r) (x << r) | (x >> (32 - r)) #endif -// Detect whether standard library has . +// Detect whether standard library has C++17 headers -#if !defined(BOOST_HASH_HAS_STRING_VIEW) && defined(__has_include) -# if __has_include() -# if defined(BOOST_MSVC) - // On Visual C++ the header exists, but causes an - // error if it isn't in C++17 mode. -# if defined(_HAS_CXX17) && _HAS_CXX17 -# define BOOST_HASH_HAS_STRING_VIEW 1 -# include -# endif -# elif defined(__cplusplus) && __cplusplus >= 201703 -# include -# define BOOST_HASH_HAS_STRING_VIEW 1 +#if !defined(BOOST_HASH_CXX17) +# if defined(BOOST_MSVC) +# if defined(_HAS_CXX17) && _HAS_CXX17 +# define BOOST_HASH_CXX17 1 # endif +# elif defined(__cplusplus) && __cplusplus >= 201703 +# define BOOST_HASH_CXX17 1 +# endif +#endif + +#if !defined(BOOST_HASH_CXX17) +# define BOOST_HASH_CXX17 0 +#endif + +#if BOOST_HASH_CXX17 && defined(__has_include) +# if !defined(BOOST_HASH_HAS_STRING_VIEW) && __has_include() +# define BOOST_HASH_HAS_STRING_VIEW 1 +# endif +# if !defined(BOOST_HASH_HAS_OPTIONAL) && __has_include() +# define BOOST_HASH_HAS_OPTIONAL 1 # endif #endif @@ -84,6 +91,18 @@ # define BOOST_HASH_HAS_STRING_VIEW 0 #endif +#if !defined(BOOST_HASH_HAS_OPTIONAL) +# define BOOST_HASH_HAS_OPTIONAL 0 +#endif + +#if BOOST_HASH_HAS_STRING_VIEW +# include +#endif + +#if BOOST_HASH_HAS_OPTIONAL +# include +#endif + namespace boost { namespace hash_detail diff --git a/test/hash_info.cpp b/test/hash_info.cpp index 8a906c3..c7b8ec8 100644 --- a/test/hash_info.cpp +++ b/test/hash_info.cpp @@ -55,9 +55,6 @@ void write_compiler_info() { if (difference) { std::cout << "+" << difference << std::endl; } -#if defined(_HAS_CXX17) && _HAS_CXX17 - std::cout << "C++17 mode" << std::endl; -#endif } #else @@ -75,10 +72,19 @@ int main() { << __cplusplus << std::endl; #endif + + std::cout << "BOOST_HASH_CXX17: " + << BOOST_HASH_CXX17 + << std::endl; + std::cout << "BOOST_HASH_HAS_STRING_VIEW: " << BOOST_HASH_HAS_STRING_VIEW << std::endl; + std::cout << "BOOST_HASH_HAS_OPTIONAL: " + << BOOST_HASH_HAS_OPTIONAL + << std::endl; + #if defined(BOOST_NO_CXX11_HDR_TYPEINDEX) std::cout << "No " << std::endl; #else