Skip to content

Commit 639a098

Browse files
authored
[libc++] mdspan - implement layout_stride (llvm#69650)
This implements layout_stride for C++23 and with that completes the implementation of the C++23 mdspan header. The feature test macro is added, and the status pages updated. Co-authored-by: Damien L-G <[email protected]> Differential Revision: https://reviews.llvm.org/D157171
1 parent 2a32afd commit 639a098

File tree

68 files changed

+2835
-108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2835
-108
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ Status
332332
--------------------------------------------------- -----------------
333333
``__cpp_lib_is_scoped_enum`` ``202011L``
334334
--------------------------------------------------- -----------------
335-
``__cpp_lib_mdspan`` *unimplemented*
335+
``__cpp_lib_mdspan`` ``202207L``
336336
--------------------------------------------------- -----------------
337337
``__cpp_lib_move_only_function`` *unimplemented*
338338
--------------------------------------------------- -----------------

libcxx/docs/Status/Cxx23.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Paper Status
4040

4141
.. note::
4242

43-
.. [#note-P0009R18] P0009R18: ``extents``, ``dextents``, ``layout_left``, ``layout_right``, and ``default_accessor`` are implemented.
4443
.. [#note-P0533R9] P0533R9: ``isfinite``, ``isinf``, ``isnan`` and ``isnormal`` are implemented.
4544
.. [#note-P1413R3] P1413R3: ``std::aligned_storage_t`` and ``std::aligned_union_t`` are marked deprecated, but
4645
clang doesn't issue a diagnostic for deprecated using template declarations.

libcxx/docs/Status/Cxx23Papers.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"`P2442R1 <https://wg21.link/P2442R1>`__","LWG","Windowing range adaptors: ``views::chunk`` and ``views::slide``","February 2022","","","|ranges|"
5252
"`P2443R1 <https://wg21.link/P2443R1>`__","LWG","``views::chunk_by``","February 2022","|Complete|","18.0","|ranges|"
5353
"","","","","","",""
54-
"`P0009R18 <https://wg21.link/P0009R18>`__","LWG","mdspan: A Non-Owning Multidimensional Array Reference","July 2022","|In progress| [#note-P0009R18]_",""
54+
"`P0009R18 <https://wg21.link/P0009R18>`__","LWG","mdspan: A Non-Owning Multidimensional Array Reference","July 2022","|Complete|","18.0"
5555
"`P0429R9 <https://wg21.link/P0429R9>`__","LWG","A Standard ``flat_map``","July 2022","",""
5656
"`P1169R4 <https://wg21.link/P1169R4>`__","LWG","``static operator()``","July 2022","|Complete|","16.0"
5757
"`P1222R4 <https://wg21.link/P1222R4>`__","LWG","A Standard ``flat_set``","July 2022","",""
@@ -89,9 +89,9 @@
8989
"`P2549R1 <https://wg21.link/P2549R1>`__","LWG","``std::unexpected`` should have ``error()`` as member accessor","July 2022","|Complete|","16.0"
9090
"`P2585R0 <https://wg21.link/P2585R0>`__","LWG","Improving default container formatting","July 2022","|Complete|","17.0"
9191
"`P2590R2 <https://wg21.link/P2590R2>`__","LWG","Explicit lifetime management","July 2022","",""
92-
"`P2599R2 <https://wg21.link/P2599R2>`__","LWG","``mdspan::size_type`` should be ``index_type``","July 2022","",""
93-
"`P2604R0 <https://wg21.link/P2604R0>`__","LWG","mdspan: rename pointer and contiguous","July 2022","",""
94-
"`P2613R1 <https://wg21.link/P2613R1>`__","LWG","Add the missing ``empty`` to ``mdspan``","July 2022","",""
92+
"`P2599R2 <https://wg21.link/P2599R2>`__","LWG","``mdspan::size_type`` should be ``index_type``","July 2022","|Complete|","18.0"
93+
"`P2604R0 <https://wg21.link/P2604R0>`__","LWG","mdspan: rename pointer and contiguous","July 2022","|Complete|","18.0"
94+
"`P2613R1 <https://wg21.link/P2613R1>`__","LWG","Add the missing ``empty`` to ``mdspan``","July 2022","|Complete|","18.0"
9595
"","","","","","",""
9696
"`P1202R5 <https://wg21.link/P1202R5>`__","LWG", "Asymmetric Fences", "November 2022","","","|concurrency TS|"
9797
"`P1264R2 <https://wg21.link/P1264R2>`__","LWG", "Revising the wording of ``stream`` input operations", "November 2022","|Complete|","9.0",""

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ set(files
508508
__mdspan/extents.h
509509
__mdspan/layout_left.h
510510
__mdspan/layout_right.h
511+
__mdspan/layout_stride.h
511512
__mdspan/mdspan.h
512513
__memory/addressof.h
513514
__memory/align.h

libcxx/include/__fwd/mdspan.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@ struct layout_right {
4242
class mapping;
4343
};
4444

45-
/*
46-
// Will be implemented with follow on revision
4745
// Layout policy with a unique mapping where strides are arbitrary
4846
struct layout_stride {
49-
template<class Extents>
50-
class mapping;
47+
template <class _Extents>
48+
class mapping;
5149
};
52-
*/
5350

5451
#endif // _LIBCPP_STD_VER >= 23
5552

libcxx/include/__mdspan/layout_left.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,27 @@ class layout_left::mapping {
110110
"layout_left::mapping converting ctor: other.required_span_size() must be representable as index_type.");
111111
}
112112

113-
// FIXME: add when we add other layouts
114-
# if 0
115-
template<class _OtherExtents>
116-
constexpr explicit(extents_type::rank() > 0)
117-
mapping(const layout_stride::mapping_<OtherExtents>&) noexcept;
118-
# endif
113+
template <class _OtherExtents>
114+
requires(is_constructible_v<extents_type, _OtherExtents>)
115+
_LIBCPP_HIDE_FROM_ABI constexpr explicit(extents_type::rank() > 0)
116+
mapping(const layout_stride::mapping<_OtherExtents>& __other) noexcept
117+
: __extents_(__other.extents()) {
118+
if constexpr (extents_type::rank() > 0) {
119+
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
120+
([&]() {
121+
using _CommonType = common_type_t<typename extents_type::index_type, typename _OtherExtents::index_type>;
122+
for (rank_type __r = 0; __r < extents_type::rank(); __r++)
123+
if (static_cast<_CommonType>(stride(__r)) != static_cast<_CommonType>(__other.stride(__r)))
124+
return false;
125+
return true;
126+
}()),
127+
"layout_left::mapping from layout_stride ctor: strides are not compatible with layout_left.");
128+
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
129+
__mdspan_detail::__is_representable_as<index_type>(__other.required_span_size()),
130+
"layout_left::mapping from layout_stride ctor: other.required_span_size() must be representable as "
131+
"index_type.");
132+
}
133+
}
119134

120135
_LIBCPP_HIDE_FROM_ABI constexpr mapping& operator=(const mapping&) noexcept = default;
121136

libcxx/include/__mdspan/layout_right.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,27 @@ class layout_right::mapping {
109109
"layout_right::mapping converting ctor: other.required_span_size() must be representable as index_type.");
110110
}
111111

112-
// FIXME: add when we add other layouts
113-
# if 0
114-
template<class _OtherExtents>
115-
constexpr explicit(extents_type::rank() > 0)
116-
mapping(const layout_stride::mapping_<OtherExtents>&) noexcept;
117-
# endif
112+
template <class _OtherExtents>
113+
requires(is_constructible_v<extents_type, _OtherExtents>)
114+
_LIBCPP_HIDE_FROM_ABI constexpr explicit(extents_type::rank() > 0)
115+
mapping(const layout_stride::mapping<_OtherExtents>& __other) noexcept
116+
: __extents_(__other.extents()) {
117+
if constexpr (extents_type::rank() > 0) {
118+
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
119+
([&]() {
120+
using _CommonType = common_type_t<typename extents_type::index_type, typename _OtherExtents::index_type>;
121+
for (rank_type __r = 0; __r < extents_type::rank(); __r++)
122+
if (static_cast<_CommonType>(stride(__r)) != static_cast<_CommonType>(__other.stride(__r)))
123+
return false;
124+
return true;
125+
}()),
126+
"layout_right::mapping from layout_stride ctor: strides are not compatible with layout_right.");
127+
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
128+
__mdspan_detail::__is_representable_as<index_type>(__other.required_span_size()),
129+
"layout_right::mapping from layout_stride ctor: other.required_span_size() must be representable as "
130+
"index_type.");
131+
}
132+
}
118133

119134
_LIBCPP_HIDE_FROM_ABI constexpr mapping& operator=(const mapping&) noexcept = default;
120135

0 commit comments

Comments
 (0)