mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 03:32:35 +08:00
First part of P1024: Usability Enhancements for std::span. Remove operator() for indexing, and add 'front' and 'back' calls.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@354801 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
28
include/span
28
include/span
@@ -88,7 +88,8 @@ public:
|
||||
|
||||
// [span.elem], span element access
|
||||
constexpr reference operator[](index_type idx) const;
|
||||
constexpr reference operator()(index_type idx) const;
|
||||
constexpr reference front() const;
|
||||
constexpr reference back() const;
|
||||
constexpr pointer data() const noexcept;
|
||||
|
||||
// [span.iterators], span iterator support
|
||||
@@ -319,10 +320,16 @@ public:
|
||||
return __data[__idx];
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr reference operator()(index_type __idx) const noexcept
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
|
||||
{
|
||||
_LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T,N>() index out of bounds");
|
||||
return __data[__idx];
|
||||
static_assert(_Extent > 0, "span<T,N>[].front() on empty span");
|
||||
return __data[0];
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept
|
||||
{
|
||||
static_assert(_Extent > 0, "span<T,N>[].back() on empty span");
|
||||
return __data[size()-1];
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; }
|
||||
@@ -484,12 +491,19 @@ public:
|
||||
return __data[__idx];
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr reference operator()(index_type __idx) const noexcept
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
|
||||
{
|
||||
_LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T>() index out of bounds");
|
||||
return __data[__idx];
|
||||
_LIBCPP_ASSERT(!empty(), "span<T>[].front() on empty span");
|
||||
return __data[0];
|
||||
}
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept
|
||||
{
|
||||
_LIBCPP_ASSERT(!empty(), "span<T>[].back() on empty span");
|
||||
return __data[size()-1];
|
||||
}
|
||||
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; }
|
||||
|
||||
// [span.iter], span iterator support
|
||||
|
||||
Reference in New Issue
Block a user