Skip to content

Commit 4e338dc

Browse files
author
Xiaoyang Liu
authored
[libc++] P2389R2: dextents Index Type Parameter (#97393)
This patch implements P2389R2, which was adopted at the St. Louis meeting. It builds upon previous enhancements from P2299R3, which introduced deduction guides and the `dextents` alias template.
1 parent 88f0dc4 commit 4e338dc

File tree

10 files changed

+74
-7
lines changed

10 files changed

+74
-7
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ Status
446446
---------------------------------------------------------- -----------------
447447
``__cpp_lib_linalg`` *unimplemented*
448448
---------------------------------------------------------- -----------------
449+
``__cpp_lib_mdspan`` ``202406L``
450+
---------------------------------------------------------- -----------------
449451
``__cpp_lib_optional_range_support`` *unimplemented*
450452
---------------------------------------------------------- -----------------
451453
``__cpp_lib_out_ptr`` *unimplemented*

libcxx/docs/ReleaseNotes/19.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Implemented Papers
5454
- P2713R1 - Escaping improvements in ``std::format``
5555
- P2231R1 - Missing ``constexpr`` in ``std::optional`` and ``std::variant``
5656
- P0019R8 - ``std::atomic_ref``
57+
- P2389R2 - Alias template ``dims`` for the ``extents`` of ``mdspan``
5758

5859
Improvements and New Features
5960
-----------------------------

libcxx/docs/Status/Cxx2cPapers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"","","","","","",""
6666
"`P2747R2 <https://wg21.link/P2747R2>`__","CWG","``constexpr`` placement new","St. Louis June 2024","","",""
6767
"`P2997R1 <https://wg21.link/P2997R1>`__","LWG","Removing the common reference requirement from the indirectly invocable concepts","St. Louis June 2024","","",""
68-
"`P2389R2 <https://wg21.link/P2389R2>`__","LWG","``dextents`` Index Type Parameter","St. Louis June 2024","","",""
68+
"`P2389R2 <https://wg21.link/P2389R2>`__","LWG","``dextents`` Index Type Parameter","St. Louis June 2024","|Complete|","19.0",""
6969
"`P3168R2 <https://wg21.link/P3168R2>`__","LWG","Give ``std::optional`` Range Support","St. Louis June 2024","","","|ranges|"
7070
"`P3217R0 <https://wg21.link/P3217R0>`__","LWG","Adjoints to 'Enabling list-initialization for algorithms': find_last","St. Louis June 2024","","",""
7171
"`P2985R0 <https://wg21.link/P2985R0>`__","LWG","A type trait for detecting virtual base classes","St. Louis June 2024","","",""

libcxx/include/__mdspan/extents.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ struct __make_dextents< _IndexType, 0, extents<_IndexType, _ExtentsPack...>> {
454454
template <class _IndexType, size_t _Rank>
455455
using dextents = typename __mdspan_detail::__make_dextents<_IndexType, _Rank>::type;
456456

457+
# if _LIBCPP_STD_VER >= 26
458+
// [mdspan.extents.dims], alias template `dims`
459+
template <size_t _Rank, class _IndexType = size_t>
460+
using dims = dextents<_IndexType, _Rank>;
461+
# endif
462+
457463
// Deduction guide for extents
458464
# if _LIBCPP_STD_VER >= 26
459465
template <class... _IndexTypes>

libcxx/include/mdspan

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ namespace std {
2020
template<class IndexType, size_t Rank>
2121
using dextents = see below;
2222
23+
// [mdspan.extents.dims], alias template dims
24+
template<size_t Rank, class IndexType = size_t>
25+
using dims = see below; // since C++26
26+
2327
// [mdspan.layout], layout mapping
2428
struct layout_left;
2529
struct layout_right;

libcxx/include/version

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ __cpp_lib_make_unique 201304L <memory>
159159
__cpp_lib_map_try_emplace 201411L <map>
160160
__cpp_lib_math_constants 201907L <numbers>
161161
__cpp_lib_math_special_functions 201603L <cmath>
162-
__cpp_lib_mdspan 202207L <mdspan>
162+
__cpp_lib_mdspan 202406L <mdspan>
163+
202207L // C++23
163164
__cpp_lib_memory_resource 201603L <memory_resource>
164165
__cpp_lib_move_iterator_concept 202207L <iterator>
165166
__cpp_lib_move_only_function 202110L <functional>
@@ -530,6 +531,8 @@ __cpp_lib_void_t 201411L <type_traits>
530531
// # define __cpp_lib_is_virtual_base_of 202406L
531532
// # define __cpp_lib_is_within_lifetime 202306L
532533
// # define __cpp_lib_linalg 202311L
534+
# undef __cpp_lib_mdspan
535+
# define __cpp_lib_mdspan 202406L
533536
// # define __cpp_lib_optional_range_support 202406L
534537
# undef __cpp_lib_out_ptr
535538
// # define __cpp_lib_out_ptr 202311L
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
9+
10+
// <mdspan>
11+
12+
// template<size_t Rank, class IndexType = size_t>
13+
// using dims = see below;
14+
//
15+
// Result: A type E that is a specialization of extents such that
16+
// E::rank() == Rank && E::rank() == E::rank_dynamic() is true,
17+
// and E::index_type denotes IndexType.
18+
19+
#include <mdspan>
20+
#include <cstddef>
21+
22+
#include "test_macros.h"
23+
24+
template <class IndexType>
25+
void test_alias_template_dims() {
26+
constexpr size_t D = std::dynamic_extent;
27+
ASSERT_SAME_TYPE(std::dims<0, IndexType>, std::extents<IndexType>);
28+
ASSERT_SAME_TYPE(std::dims<1, IndexType>, std::extents<IndexType, D>);
29+
ASSERT_SAME_TYPE(std::dims<2, IndexType>, std::extents<IndexType, D, D>);
30+
ASSERT_SAME_TYPE(std::dims<3, IndexType>, std::extents<IndexType, D, D, D>);
31+
ASSERT_SAME_TYPE(std::dims<9, IndexType>, std::extents<IndexType, D, D, D, D, D, D, D, D, D>);
32+
}
33+
34+
template <>
35+
void test_alias_template_dims<size_t>() {
36+
constexpr size_t D = std::dynamic_extent;
37+
ASSERT_SAME_TYPE(std::dims<0>, std::extents<size_t>);
38+
ASSERT_SAME_TYPE(std::dims<1>, std::extents<size_t, D>);
39+
ASSERT_SAME_TYPE(std::dims<2>, std::extents<size_t, D, D>);
40+
ASSERT_SAME_TYPE(std::dims<3>, std::extents<size_t, D, D, D>);
41+
ASSERT_SAME_TYPE(std::dims<9>, std::extents<size_t, D, D, D, D, D, D, D, D, D>);
42+
}
43+
44+
int main(int, char**) {
45+
test_alias_template_dims<int>();
46+
test_alias_template_dims<unsigned int>();
47+
test_alias_template_dims<size_t>();
48+
return 0;
49+
}

libcxx/test/std/language.support/support.limits/support.limits.general/mdspan.version.compile.pass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/* Constant Value
1919
__cpp_lib_freestanding_mdspan 202311L [C++26]
2020
__cpp_lib_mdspan 202207L [C++23]
21+
202406L [C++26]
2122
__cpp_lib_submdspan 202306L [C++26]
2223
*/
2324

@@ -115,8 +116,8 @@
115116
# ifndef __cpp_lib_mdspan
116117
# error "__cpp_lib_mdspan should be defined in c++26"
117118
# endif
118-
# if __cpp_lib_mdspan != 202207L
119-
# error "__cpp_lib_mdspan should have the value 202207L in c++26"
119+
# if __cpp_lib_mdspan != 202406L
120+
# error "__cpp_lib_mdspan should have the value 202406L in c++26"
120121
# endif
121122

122123
# if !defined(_LIBCPP_VERSION)

libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
__cpp_lib_math_constants 201907L [C++20]
148148
__cpp_lib_math_special_functions 201603L [C++17]
149149
__cpp_lib_mdspan 202207L [C++23]
150+
202406L [C++26]
150151
__cpp_lib_memory_resource 201603L [C++17]
151152
__cpp_lib_modules 202207L [C++23]
152153
__cpp_lib_move_iterator_concept 202207L [C++20]
@@ -7289,8 +7290,8 @@
72897290
# ifndef __cpp_lib_mdspan
72907291
# error "__cpp_lib_mdspan should be defined in c++26"
72917292
# endif
7292-
# if __cpp_lib_mdspan != 202207L
7293-
# error "__cpp_lib_mdspan should have the value 202207L in c++26"
7293+
# if __cpp_lib_mdspan != 202406L
7294+
# error "__cpp_lib_mdspan should have the value 202406L in c++26"
72947295
# endif
72957296

72967297
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_PMR

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ def add_version_header(tc):
868868
"name": "__cpp_lib_mdspan",
869869
"values": {
870870
"c++23": 202207,
871-
# "c++26": 202406, # P2389R2 dextents Index Type Parameter
871+
"c++26": 202406, # P2389R2 dextents Index Type Parameter
872872
},
873873
"headers": ["mdspan"],
874874
},

0 commit comments

Comments
 (0)