Clean up header detection for more headers + add optional

This commit is contained in:
Daniel James
2018-01-21 18:21:46 +00:00
parent 42bb81befa
commit b9ae7e7fb6
2 changed files with 41 additions and 16 deletions

View File

@@ -62,21 +62,28 @@
# define BOOST_FUNCTIONAL_HASH_ROTL32(x, r) (x << r) | (x >> (32 - r)) # define BOOST_FUNCTIONAL_HASH_ROTL32(x, r) (x << r) | (x >> (32 - r))
#endif #endif
// Detect whether standard library has <string_view>. // Detect whether standard library has C++17 headers
#if !defined(BOOST_HASH_HAS_STRING_VIEW) && defined(__has_include) #if !defined(BOOST_HASH_CXX17)
# if __has_include(<string_view>) # if defined(BOOST_MSVC)
# if defined(BOOST_MSVC) # if defined(_HAS_CXX17) && _HAS_CXX17
// On Visual C++ the header exists, but causes an # define BOOST_HASH_CXX17 1
// error if it isn't in C++17 mode.
# if defined(_HAS_CXX17) && _HAS_CXX17
# define BOOST_HASH_HAS_STRING_VIEW 1
# include <string_view>
# endif
# elif defined(__cplusplus) && __cplusplus >= 201703
# include <string_view>
# define BOOST_HASH_HAS_STRING_VIEW 1
# endif # 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(<string_view>)
# define BOOST_HASH_HAS_STRING_VIEW 1
# endif
# if !defined(BOOST_HASH_HAS_OPTIONAL) && __has_include(<optional>)
# define BOOST_HASH_HAS_OPTIONAL 1
# endif # endif
#endif #endif
@@ -84,6 +91,18 @@
# define BOOST_HASH_HAS_STRING_VIEW 0 # define BOOST_HASH_HAS_STRING_VIEW 0
#endif #endif
#if !defined(BOOST_HASH_HAS_OPTIONAL)
# define BOOST_HASH_HAS_OPTIONAL 0
#endif
#if BOOST_HASH_HAS_STRING_VIEW
# include <string_view>
#endif
#if BOOST_HASH_HAS_OPTIONAL
# include <optional>
#endif
namespace boost namespace boost
{ {
namespace hash_detail namespace hash_detail

View File

@@ -55,9 +55,6 @@ void write_compiler_info() {
if (difference) { if (difference) {
std::cout << "+" << difference << std::endl; std::cout << "+" << difference << std::endl;
} }
#if defined(_HAS_CXX17) && _HAS_CXX17
std::cout << "C++17 mode" << std::endl;
#endif
} }
#else #else
@@ -75,10 +72,19 @@ int main() {
<< __cplusplus << __cplusplus
<< std::endl; << std::endl;
#endif #endif
std::cout << "BOOST_HASH_CXX17: "
<< BOOST_HASH_CXX17
<< std::endl;
std::cout << "BOOST_HASH_HAS_STRING_VIEW: " std::cout << "BOOST_HASH_HAS_STRING_VIEW: "
<< BOOST_HASH_HAS_STRING_VIEW << BOOST_HASH_HAS_STRING_VIEW
<< std::endl; << std::endl;
std::cout << "BOOST_HASH_HAS_OPTIONAL: "
<< BOOST_HASH_HAS_OPTIONAL
<< std::endl;
#if defined(BOOST_NO_CXX11_HDR_TYPEINDEX) #if defined(BOOST_NO_CXX11_HDR_TYPEINDEX)
std::cout << "No <typeindex>" << std::endl; std::cout << "No <typeindex>" << std::endl;
#else #else