summaryrefslogtreecommitdiffstats
path: root/libcxx/include/span
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2019-02-25 17:54:08 +0000
committerMarshall Clow <mclow.lists@gmail.com>2019-02-25 17:54:08 +0000
commit9ab85a69dcee63c3f54214bb4495e6d20f7ec100 (patch)
tree79e08ead0300685226f2b0d5c1ff70a6e7bb6eae /libcxx/include/span
parenta64de6720b5480d909371692bef31549b71f99a6 (diff)
downloadbcm5719-llvm-9ab85a69dcee63c3f54214bb4495e6d20f7ec100.tar.gz
bcm5719-llvm-9ab85a69dcee63c3f54214bb4495e6d20f7ec100.zip
First part of P1024: Usability Enhancements for std::span. Remove operator() for indexing, and add 'front' and 'back' calls.
llvm-svn: 354801
Diffstat (limited to 'libcxx/include/span')
-rw-r--r--libcxx/include/span28
1 files changed, 21 insertions, 7 deletions
diff --git a/libcxx/include/span b/libcxx/include/span
index 774f69823bd..b212f8722be 100644
--- a/libcxx/include/span
+++ b/libcxx/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
OpenPOWER on IntegriCloud