Skip to content

Commit

Permalink
Improve detection of C++17 deduction guides (#48, #61)
Browse files Browse the repository at this point in the history
Class template argument deduction (CTAD)

Affects:
- VS2019, MSVC++ 14.2  _MSC_VER >= 1920
- VS2017, MSVC++ 14.1, _MSC_VER >= 1910
  • Loading branch information
martinmoene committed Nov 24, 2020
1 parent 3c0f499 commit acf4df1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions include/nonstd/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) )
Expand All @@ -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<End, std::size_t>::value ))
>
Expand Down Expand Up @@ -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;
Expand All @@ -1298,7 +1302,7 @@ class span
{
return to_address( it.operator->() );
}
#endif
#endif // span_HAVE( ITERATOR_CTOR )

private:
pointer data_;
Expand All @@ -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<T, static_cast<extent_t>(N)>;
Expand Down

0 comments on commit acf4df1

Please sign in to comment.