Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions stl/inc/span
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ public:
}
#endif // _MSVC_STL_HARDENING_SPAN || _ITERATOR_DEBUG_LEVEL != 0

return span<element_type, _Count>{_Mydata, _Count};
return span<element_type, _Count>(_Mydata, _Count);
}

_NODISCARD constexpr auto first(const size_type _Count) const noexcept /* strengthened */ {
#if _MSVC_STL_HARDENING_SPAN || _ITERATOR_DEBUG_LEVEL != 0
_STL_VERIFY(_Count <= _Mysize, "Count out of range in span::first(count)");
#endif

return span<element_type, dynamic_extent>{_Mydata, _Count};
return span<element_type, dynamic_extent>(_Mydata, _Count);
}

template <size_t _Count>
Expand All @@ -397,15 +397,15 @@ public:
}
#endif // _MSVC_STL_HARDENING_SPAN || _ITERATOR_DEBUG_LEVEL != 0

return span<element_type, _Count>{_Mydata + (_Mysize - _Count), _Count};
return span<element_type, _Count>(_Mydata + (_Mysize - _Count), _Count);
}

_NODISCARD constexpr auto last(const size_type _Count) const noexcept /* strengthened */ {
#if _MSVC_STL_HARDENING_SPAN || _ITERATOR_DEBUG_LEVEL != 0
_STL_VERIFY(_Count <= _Mysize, "Count out of range in span::last(count)");
#endif

return span<element_type, dynamic_extent>{_Mydata + (_Mysize - _Count), _Count};
return span<element_type, dynamic_extent>(_Mydata + (_Mysize - _Count), _Count);
}

template <size_t _Offset, size_t _Count = dynamic_extent>
Expand All @@ -427,7 +427,7 @@ public:

using _ReturnType = span<element_type,
_Count != dynamic_extent ? _Count : (_Extent != dynamic_extent ? _Extent - _Offset : dynamic_extent)>;
return _ReturnType{_Mydata + _Offset, _Count == dynamic_extent ? _Mysize - _Offset : _Count};
return _ReturnType(_Mydata + _Offset, _Count == dynamic_extent ? _Mysize - _Offset : _Count);
}

_NODISCARD constexpr auto subspan(const size_type _Offset, const size_type _Count = dynamic_extent) const noexcept
Expand All @@ -439,7 +439,7 @@ public:
#endif // _MSVC_STL_HARDENING_SPAN || _ITERATOR_DEBUG_LEVEL != 0

using _ReturnType = span<element_type, dynamic_extent>;
return _ReturnType{_Mydata + _Offset, _Count == dynamic_extent ? _Mysize - _Offset : _Count};
return _ReturnType(_Mydata + _Offset, _Count == dynamic_extent ? _Mysize - _Offset : _Count);
}

// [span.obs] Observers
Expand Down
51 changes: 51 additions & 0 deletions tests/std/tests/P0122R7_span/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <array>
#include <cassert>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <iterator>
Expand Down Expand Up @@ -996,6 +997,56 @@ constexpr bool test() {
static_assert(is_same_v<decltype(sp_nine.rend()), span<int, 9>::reverse_iterator>);
}

{
bool sequence[9]{true, false, true, false, true, false, true, false, true};

const span<const bool> sp_dyn(sequence);
const span<const bool, 9> sp_nine(sequence);

same_as<span<const bool>> decltype(auto) first_1 = sp_dyn.first(4);
same_as<span<const bool, 4>> decltype(auto) first_2 = sp_nine.first<4>();
static_assert(noexcept(sp_dyn.first(4))); // strengthened
static_assert(noexcept(sp_nine.first<4>())); // strengthened
assert(first_1.data() == begin(sequence));
assert(first_2.data() == begin(sequence));
assert(first_1.size() == 4);
assert(first_2.size() == 4);
assert(first_1[3] == false);
assert(first_2[3] == false);

same_as<span<const bool>> decltype(auto) last_1 = sp_dyn.last(4);
same_as<span<const bool, 4>> decltype(auto) last_2 = sp_nine.last<4>();
static_assert(noexcept(sp_dyn.last(4))); // strengthened
static_assert(noexcept(sp_nine.last<4>())); // strengthened
assert(last_1.data() == begin(sequence) + 5);
assert(last_2.data() == begin(sequence) + 5);
assert(last_1.size() == 4);
assert(last_2.size() == 4);
assert(last_1[0] == false);
assert(last_2[3] == true);

same_as<span<const bool>> decltype(auto) subspan_1 = sp_dyn.subspan(3, 4);
same_as<span<const bool>> decltype(auto) subspan_2 = sp_dyn.subspan(3);
same_as<span<const bool, 4>> decltype(auto) subspan_3 = sp_nine.subspan<3, 4>();
same_as<span<const bool, 6>> decltype(auto) subspan_4 = sp_nine.subspan<3>();
static_assert(noexcept(sp_dyn.subspan(3, 4))); // strengthened
static_assert(noexcept(sp_dyn.subspan(3))); // strengthened
static_assert(noexcept(sp_nine.subspan<3, 4>())); // strengthened
static_assert(noexcept(sp_nine.subspan<3>())); // strengthened
assert(subspan_1.data() == begin(sequence) + 3);
assert(subspan_2.data() == begin(sequence) + 3);
assert(subspan_3.data() == begin(sequence) + 3);
assert(subspan_4.data() == begin(sequence) + 3);
assert(subspan_1.size() == 4);
assert(subspan_2.size() == 6);
assert(subspan_3.size() == 4);
assert(subspan_4.size() == 6);
assert(subspan_1[0] == false);
assert(subspan_2[5] == true);
assert(subspan_3[0] == false);
assert(subspan_4[5] == true);
}

return true;
}

Expand Down