[libcxx-commits] [libcxx] [libc++][mdspan] P3383R3: `mdspan.at()` (PR #175213)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue May 19 06:13:42 PDT 2026
================
@@ -217,6 +219,37 @@ class mdspan {
}(make_index_sequence<rank()>()));
}
+# if _LIBCPP_STD_VER >= 26
+ template <class... _OtherIndexTypes>
+ requires((is_convertible_v<_OtherIndexTypes, index_type> && ...) &&
+ (is_nothrow_constructible_v<index_type, _OtherIndexTypes> && ...) &&
+ (sizeof...(_OtherIndexTypes) == rank()))
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference at(_OtherIndexTypes... __indices) const {
+ if (!__mdspan_detail::__is_multidimensional_index_in(__map_.extents(), __indices...)) {
+ __throw_out_of_range();
+ }
+ return (*this)[extents_type::__index_cast(std::move(__indices))...];
+ }
+
+ template <class _OtherIndexType>
+ requires(is_convertible_v<const _OtherIndexType&, index_type> &&
+ is_nothrow_constructible_v<index_type, const _OtherIndexType&>)
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr reference at(const array<_OtherIndexType, rank()>& __indices) const {
+ return [&]<size_t... _Idxs>(index_sequence<_Idxs...>) -> reference {
+ return at(extents_type::__index_cast(as_const(__indices[_Idxs]))...);
----------------
frederick-vs-ja wrote:
`__indices[_Idxs]...` are obviously already `const`.
```suggestion
return at(extents_type::__index_cast(__indices[_Idxs])...);
```
https://github.com/llvm/llvm-project/pull/175213
More information about the libcxx-commits
mailing list