[libcxx-commits] [PATCH] D151267: mdspan: implement layout_right

Christian Trott via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 26 10:47:37 PDT 2023


crtrott added inline comments.


================
Comment at: libcxx/include/__mdspan/layout_right_mapping.h:155
+                   "layout_right::mapping: out of bounds indexing");
+    return __compute_offset(__rank_count<0, extents_type::rank()>(), static_cast<index_type>(__idx)...);
+  }
----------------
ldionne wrote:
> ```
> return [&]<size_t ..._Pos>(index_sequence<_Pos...>) {
>   index_type __result = 0;
>   ((result = __idx + __extents_.extent(_Pos) * __result))...; // exercise for the reader :-)
>   return __result;
> }(index_sequence_for<_Indices...>{});
> ```
> 
```
 template<class ... _Indices>
 constexpr index_type  operator() (_Indices ... __idx) const {
    return [&]<size_t ... _Pos>(index_sequence<_Pos...>) {
      index_type __res = 0;
      ((__res = static_cast<index_type>(__idx) + __extents_.extent(_Pos) * __res),...);
      return __res;
    }(make_index_sequence<sizeof...(_Indices)>());
  }
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151267/new/

https://reviews.llvm.org/D151267



More information about the libcxx-commits mailing list