else
static_assert(_Count <= extent);
using _Sp = span<element_type, _Count>;
- return _Sp{ _SizedPtr{this->data()} };
+ return _Sp(_SizedPtr{this->data()});
}
[[nodiscard]]
first(size_type __count) const noexcept
{
__glibcxx_assert(__count <= size());
- return { this->data(), __count };
+ return span<element_type>(this->data(), __count);
}
template<size_t _Count>
else
static_assert(_Count <= extent);
using _Sp = span<element_type, _Count>;
- return _Sp{ _SizedPtr{this->data() + (this->size() - _Count)} };
+ return _Sp(_SizedPtr{this->data() + (this->size() - _Count)});
}
[[nodiscard]]
last(size_type __count) const noexcept
{
__glibcxx_assert(__count <= size());
- return { this->data() + (this->size() - __count), __count };
+ return span<element_type>(this->data() + (this->size() - __count),
+ __count);
}
template<size_t _Offset, size_t _Count = dynamic_extent>
using _Sp = span<element_type, _S_subspan_extent<_Offset, _Count>()>;
if constexpr (_Count == dynamic_extent)
- return _Sp{ this->data() + _Offset, this->size() - _Offset };
+ return _Sp(this->data() + _Offset, this->size() - _Offset);
else
{
if constexpr (_Extent == dynamic_extent)
static_assert(_Count <= extent);
static_assert(_Count <= (extent - _Offset));
}
- return _Sp{ _SizedPtr{this->data() + _Offset} };
+ return _Sp(_SizedPtr{this->data() + _Offset});
}
}
__glibcxx_assert(__count <= size());
__glibcxx_assert(__offset + __count <= size());
}
- return {this->data() + __offset, __count};
+ return span<element_type>(this->data() + __offset, __count);
}
private:
--- /dev/null
+// { dg-do run { target c++26 } }
+
+#include <span>
+#include <testsuite_hooks.h>
+
+void
+test_first()
+{
+ bool arr[5];
+ std::span<const bool> s(arr);
+ std::span<const bool> s2 = s.first(5);
+ VERIFY( s2.data() == s.data() );
+ std::span<const bool> s3 = s.first<5>();
+ VERIFY( s3.data() == s.data() );
+}
+
+void
+test_last()
+{
+ bool arr[5];
+ std::span<const bool> s(arr);
+ std::span<const bool> s2 = s.last(5);
+ VERIFY( s2.data() == s.data() );
+ std::span<const bool> s3 = s.last<5>();
+ VERIFY( s3.data() == s.data() );
+}
+
+void
+test_subspan()
+{
+ bool arr[5];
+ std::span<const bool> s(arr);
+ std::span<const bool> s2 = s.subspan(0, 5);
+ VERIFY( s2.data() == s.data() );
+ std::span<const bool> s3 = s.subspan<0>();
+ VERIFY( s3.data() == s.data() );
+ std::span<const bool> s4 = s.subspan<0, 5>();
+ VERIFY( s4.data() == s.data() );
+}
+
+int main()
+{
+ test_first();
+ test_last();
+ test_subspan();
+}