aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/span
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2024-01-09 19:58:18 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-01-09 19:58:18 +0000
commitaca2e42c67292825f835f094eb0c4df5ce6013db (patch)
tree9cfb7eeef35545100c4f7219e794e6a0306ea6a6 /libcxx/include/span
parent77dbea07356e1ab2f37a777d4d1ddc5dd3e301c2 (diff)
downloadsrc-aca2e42c67292825f835f094eb0c4df5ce6013db.tar.gz
src-aca2e42c67292825f835f094eb0c4df5ce6013db.zip
Diffstat (limited to 'libcxx/include/span')
-rw-r--r--libcxx/include/span18
1 files changed, 18 insertions, 0 deletions
diff --git a/libcxx/include/span b/libcxx/include/span
index 7dd53110ac29..007a32597f96 100644
--- a/libcxx/include/span
+++ b/libcxx/include/span
@@ -92,6 +92,7 @@ public:
// [span.elem], span element access
constexpr reference operator[](size_type idx) const;
+ constexpr reference at(size_type idx) const; // since C++26
constexpr reference front() const;
constexpr reference back() const;
constexpr pointer data() const noexcept;
@@ -146,6 +147,7 @@ template<class R>
#include <__utility/forward.h>
#include <array> // for array
#include <cstddef> // for byte
+#include <stdexcept>
#include <version>
// standard-mandated includes
@@ -321,6 +323,14 @@ public:
return __data_[__idx];
}
+# if _LIBCPP_STD_VER >= 26
+ _LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __index) const {
+ if (__index >= size())
+ std::__throw_out_of_range("span");
+ return __data_[__index];
+ }
+# endif
+
_LIBCPP_HIDE_FROM_ABI constexpr reference front() const noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T, N>::front() on empty span");
return __data_[0];
@@ -469,6 +479,14 @@ public:
return __data_[__idx];
}
+# if _LIBCPP_STD_VER >= 26
+ _LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __index) const {
+ if (__index >= size())
+ std::__throw_out_of_range("span");
+ return __data_[__index];
+ }
+# endif
+
_LIBCPP_HIDE_FROM_ABI constexpr reference front() const noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T>::front() on empty span");
return __data_[0];