From acf4df1ab4b75b3c3be76bd6bf22d29361909f17 Mon Sep 17 00:00:00 2001 From: Martin Moene Date: Tue, 24 Nov 2020 14:10:35 +0100 Subject: [PATCH] Improve detection of C++17 deduction guides (#48, #61) Class template argument deduction (CTAD) Affects: - VS2019, MSVC++ 14.2 _MSC_VER >= 1920 - VS2017, MSVC++ 14.1, _MSC_VER >= 1910 --- include/nonstd/span.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/nonstd/span.hpp b/include/nonstd/span.hpp index 691bd37..edcf2d8 100644 --- a/include/nonstd/span.hpp +++ b/include/nonstd/span.hpp @@ -342,7 +342,11 @@ span_DISABLE_MSVC_WARNINGS( 26439 26440 26472 26473 26481 26490 ) // MSVC: template parameter deduction guides since Visual Studio 2017 v15.7 -#define span_HAVE_DEDUCTION_GUIDES (span_CPP17_OR_GREATER && ! span_BETWEEN( span_COMPILER_MSVC_VER, 1, 1913 )) +#if defined(__cpp_deduction_guides) +# define span_HAVE_DEDUCTION_GUIDES 1 +#else +# define span_HAVE_DEDUCTION_GUIDES (span_CPP17_OR_GREATER && ! span_BETWEEN( span_COMPILER_MSVC_VER, 1, 1913 )) +#endif // Presence of C++ library features: @@ -624,7 +628,7 @@ using void_t = void; using std::data; using std::size; -#elif span_HAVE_CONSTRAINED_SPAN_CONTAINER_CTOR +#elif span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) template< typename T, std::size_t N > inline span_constexpr auto size( const T(&)[N] ) span_noexcept -> size_t @@ -897,7 +901,7 @@ class span // span_EXPECTS( size() == 0 ); } -#if span_HAVE_ITERATOR_CTOR +#if span_HAVE( ITERATOR_CTOR ) template< typename It > span_constexpr_exp span( It first, size_type count ) : data_( to_address( first ) ) @@ -920,7 +924,7 @@ class span } #endif -#if span_HAVE_ITERATOR_CTOR +#if span_HAVE( ITERATOR_CTOR ) template< typename It, typename End span_REQUIRES_T(( ! std::is_convertible::value )) > @@ -1279,7 +1283,7 @@ class span private: -#if span_HAVE_ITERATOR_CTOR +#if span_HAVE( ITERATOR_CTOR ) static inline span_constexpr pointer to_address( std::nullptr_t ) span_noexcept { return nullptr; @@ -1298,7 +1302,7 @@ class span { return to_address( it.operator->() ); } -#endif +#endif // span_HAVE( ITERATOR_CTOR ) private: pointer data_; @@ -1307,7 +1311,7 @@ class span // class template argument deduction guides: -#if span_HAVE( DEDUCTION_GUIDES ) // span_CPP17_OR_GREATER +#if span_HAVE( DEDUCTION_GUIDES ) template< class T, size_t N > span( T (&)[N] ) -> span(N)>;