Skip to content

Commit 1264531

Browse files
committed
Release 0.9.2 fixes #64
Note: With MSVC Debug, a span cannot be created from an empty range, like: std::vector v; span(v.begin(),v.end()). This behaviour is present since the introduction of construction from iterators in v0.9.0.
1 parent c06ecb3 commit 1264531

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

include/nonstd/span.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,8 @@ class span
12991299

13001300
private:
13011301

1302+
// Note: C++20 has std::pointer_traits<Ptr>::to_address( it );
1303+
13021304
#if span_HAVE( ITERATOR_CTOR )
13031305
static inline span_constexpr pointer to_address( std::nullptr_t ) span_noexcept
13041306
{

test/span-main.t.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ CASE( "Presence of C++ language features" "[.stdlanguage]" )
155155
span_ABSENT( _CPPUNWIND );
156156
#endif
157157

158+
#if defined(_DEBUG)
159+
span_PRESENT( _DEBUG );
160+
#else
161+
span_ABSENT( _DEBUG );
162+
#endif
163+
164+
#if defined(NDEBUG)
165+
span_PRESENT( NDEBUG );
166+
#else
167+
span_ABSENT( NDEBUG );
168+
#endif
169+
158170
#if span_USES_STD_SPAN
159171
std::cout << "(Presence of C++ language features not available: using std::span)\n";
160172
#else

test/span.t.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,15 @@ CASE( "span<>: Allows to construct from two iterators" )
228228
CASE( "span<>: Allows to construct from two iterators - empty range" )
229229
{
230230
#if span_HAVE_ITERATOR_CTOR
231+
#if ! (span_COMPILER_MSVC_VER && defined(_DEBUG) )
231232
std::vector<int> v;
232233

233-
span<int> s( v.begin(), v.end() );
234+
span<int> s( v.begin(), v.end() );
234235

235-
EXPECT( std::equal( s.begin(), s.end(), v.begin() ) );
236+
EXPECT( std::equal( s.begin(), s.end(), v.begin() ) );
237+
#else
238+
EXPECT( !!"construction from empty range not available (MSVC Debug)" );
239+
#endif
236240
#else
237241
EXPECT( !!"construction from iterator is not available (no C++11)" );
238242
#endif
@@ -254,11 +258,15 @@ CASE( "span<>: Allows to construct from an iterator and a size" )
254258
CASE( "span<>: Allows to construct from an iterator and a size - empty range" )
255259
{
256260
#if span_HAVE_ITERATOR_CTOR
261+
#if ! (span_COMPILER_MSVC_VER && defined(_DEBUG) )
257262
std::vector<int> v;
258263

259264
span<int> s( v.begin(), v.size() );
260265

261266
EXPECT( std::equal( s.begin(), s.end(), v.begin() ) );
267+
#else
268+
EXPECT( !!"construction from empty range not available (MSVC Debug)" );
269+
#endif
262270
#else
263271
EXPECT( !!"construction from iterator is not available (no C++11)" );
264272
#endif

0 commit comments

Comments
 (0)