diff options
Diffstat (limited to 'libcxx/include/span')
-rw-r--r-- | libcxx/include/span | 18 |
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]; |