aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/mdspan
AgeCommit message (Collapse)AuthorFilesLines
7 dayslibstdc++: Fix style issues in <mdspan>.Luc Grosheintz1-13/+4
libstdc++-v3/ChangeLog: * include/std/mdspan: Small stylistic adjustments. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
14 dayslibstdc++: Make the default ctor of mdspan conditionally noexcept.Luc Grosheintz1-7/+5
Previously, the default ctor of mdspan was never noexcept, even if all members of mdspan were nothrow default constructible. This commit makes mdspan conditionally nothrow default constructible. A similar strengthening happens in libc++. libstdc++-v3/ChangeLog: * include/std/mdspan (mdspan::mdspan): Make default ctor conditionally noexcept. * testsuite/23_containers/mdspan/mdspan.cc: Add tests. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
14 dayslibstdc++: Strengthen exception guarantee for mdspan methods.Luc Grosheintz1-6/+16
The mdspan::is_{,always}_{unique,strided,exhaustive} methods only call their counterparts in mdspan::mapping_type. The standard specifies that the methods of mdspan::mapping_type are noexcept, but doesn't specify if the methods of mdspan are noexcept. Libc++ strengthened the exception guarantee for these mdspan methods. This commit conditionally strengthens these methods for libstdc++. libstdc++-v3/ChangeLog: * include/std/mdspan (mdspan::is_always_unique): Make conditionally noexcept. (mdspan::is_always_exhaustive): Ditto. (mdspan::is_always_strided): Ditto. (mdspan::is_unique): Ditto. (mdspan::is_exhaustive): Ditto. (mdspan::is_strided): Ditto. * testsuite/23_containers/mdspan/layout_like.h: Make noexcept configurable. Add ThrowingLayout. * testsuite/23_containers/mdspan/mdspan.cc: Add tests for noexcept. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-07-17libstdc++: Fix forwarding of custom IndexType in mdspan [PR121061]Luc Grosheintz1-4/+4
The second bug report in PR121061 is that the conversion of custom OtherIndexType to IndexType is incorrectly not done via r-value references. This commit fixes the forwarding issue, adds a custom IndexType called RValueInt, which only allows conversion to int via r-value reference. PR libstdc++/121061 libstdc++-v3/ChangeLog: * include/std/mdspan (extents::extents): Perform conversion to index_type of an r-value reference. (layout_left::mapping::operator()): Ditto. (layout_right::mapping::operator()): Ditto. (layout_stride::mapping::operator()): Ditto. * testsuite/23_containers/mdspan/extents/custom_integer.cc: Add tests for RValueInt and MutatingInt. * testsuite/23_containers/mdspan/int_like.h (RValueInt): Add. * testsuite/23_containers/mdspan/layouts/mapping.cc: Test with RValueInt. * testsuite/23_containers/mdspan/mdspan.cc: Ditto. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-07-17libstdc++: Fix constraint for custom integer types in mdspan [PR121061]Luc Grosheintz1-14/+20
PR121061 consists of two bugs for mdspan related code. This commit fixes the first one. Namely, when passing custom IndexType as an array or span, the conversion to int must be const. Prior to this commit the constraint incorrectly also allowed non-const conversion. This commit updates all related constraints to check __valid_index_type<const OtherIndexType&, index_type> in those cases. Also adds a MutatingInt to int_like.h which only supports non-const conversion to int and updates the tests. PR libstdc++/121061 libstdc++-v3/ChangeLog: * include/std/mdspan (extents::extents): Fix constraint to prevent non-const conversion to index_type. (layout_stride::mapping::mapping): Ditto. (mdspan::mdspan): Ditto. (mdspan::operator[]): Ditto. * testsuite/23_containers/mdspan/extents/custom_integer.cc: Add test for MutatingInt. * testsuite/23_containers/mdspan/int_like.h (MutatingInt): Add. * testsuite/23_containers/mdspan/layouts/mapping.cc: Add test for MutatingInt. * testsuite/23_containers/mdspan/layouts/stride.cc: Ditto. * testsuite/23_containers/mdspan/mdspan.cc: Ditto. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-07-09libstdc++: Add more template keywords to <mdspan> for ClangJonathan Wakely1-2/+2
This fixes: include/c++/16.0.0/mdspan:1182:33: error: use 'template' keyword to treat 'mapping' as a dependent template name 1182 | const typename _OLayout::mapping<_OExtents>&> | ^ include/c++/16.0.0/mdspan:1185:31: error: use 'template' keyword to treat 'mapping' as a dependent template name 1185 | const typename _OLayout::mapping<_OExtents>&, mapping_type> | ^ libstdc++-v3/ChangeLog: * include/std/mdspan (mdspan): Add template keyword for dependent name.
2025-07-08libstdc++: Better CTAD for span and mdspan [PR120914].Luc Grosheintz1-6/+2
This implements P3029R1. In P3029R1, the CTAD for span is refined to permit deducing the extent of the span from an integral constant, e.g. span((T*) ptr, integral_constant<size_t, 5>{}); is deduced as span<T, 5>. Similarly, in auto exts = extents(integral_constant<int, 2>); auto md = mdspan((T*) ptr, integral_constant<int, 2>); exts and md have types extents<size_t, 2> and mdspan<double, extents<size_t, 2>>, respectively. PR libstdc++/120914 libstdc++-v3/ChangeLog: * include/std/span (span): Update CTAD to enable integral constants [P3029R1]. * include/std/mdspan (extents): ditto. (mdspan): ditto. * testsuite/23_containers/span/deduction.cc: Test deduction guide. * testsuite/23_containers/mdspan/extents/misc.cc: ditto. * testsuite/23_containers/mdspan/mdspan.cc: ditto. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-07-08libstdc++: Implement mdspan and tests [PR107761].Luc Grosheintz1-0/+285
Implements the class mdspan as described in N4950, i.e. without P3029. It also adds tests for mdspan. This commit completes the implementation of P0009, i.e. the C++23 part <mdspan>. PR libstdc++/107761 libstdc++-v3/ChangeLog: * include/std/mdspan (mdspan): New class. * src/c++23/std.cc.in (mdspan): Add. * testsuite/23_containers/mdspan/class_mandate_neg.cc: New test. * testsuite/23_containers/mdspan/mdspan.cc: New test. * testsuite/23_containers/mdspan/layout_like.h: Add class LayoutLike which models a user-defined layout. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-07-08libstdc++: Implement __mdspan::__size.Luc Grosheintz1-4/+8
The current code uses __mdspan::__fwd_prod(__exts, __rank) to express computing the size of an extent. This commit adds an function __mdspan:: __size(__exts) to express the idea more directly. libstdc++-v3/ChangeLog: * include/std/mdspan (__mdspan::__size): New function. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-07-08libstdc++: Check prerequisite of extents::extents.Luc Grosheintz1-0/+13
Previously the prerequisite of the extents ctors that static_extent(i) == dynamic_extent || extent(i) == other.extent(i). was not checked. This commit adds the __glibcxx_assert and test them. libstdc++-v3/ChangeLog: * include/std/mdspan (extents): Check prerequisite of the ctor that static_extent(i) == dynamic_extent || extent(i) == other.extent(i). * testsuite/23_containers/mdspan/extents/class_mandates_neg.cc: Test the implemented prerequisite. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-07-08libstdc++: Check prerequisites of layout_*::operator().Luc Grosheintz1-0/+5
Previously, the prerequisite that the arguments passed to operator() are a multi-dimensional index (of extents()) was not checked. Both mapping::operator() and mdspan::operator[] have the same prerequisite. Since, mdspan must check the prerequisite for user-defined layout mappings, the preference is to check in mdspan. Because out-of-bounds accesses are very common it's nevertheless useful to check the prerequisite in mapping::operator(). This is relevant for cases where the layout mappings are used without mdspan. This commit checks the prerequisites via _GLIBCXX_DEBUG_ASSERTs and adds the required tests. More discussion in the email chain starting at: https://gcc.gnu.org/pipermail/libstdc++/2025-July/062265.html libstdc++-v3/ChangeLog: * include/std/mdspan: Check prerequisites of layout_*::operator() with _GLIBCXX_DEBUG_ASSERTs. * testsuite/23_containers/mdspan/layouts/debug/out_of_bounds_neg.cc: Add tests for prerequisites. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-07-07libstdc++: Use template keyword in __mapping_of alias templateJonathan Wakely1-1/+1
This is needed to fix an error with Clang 19: include/c++/16.0.0/mdspan:512:30: error: use 'template' keyword to treat 'mapping' as a dependent template name 512 | is_same_v<typename _Layout::mapping<typename _Mapping::extents_type>, | ^ libstdc++-v3/ChangeLog: * include/std/mdspan (__mapping_of): Add template keyword.
2025-07-01libstdc++: Implement default_accessor from mdspan.Luc Grosheintz1-0/+31
libstdc++-v3/ChangeLog: * include/std/mdspan (default_accessor): New class. * src/c++23/std.cc.in: Register default_accessor. * testsuite/23_containers/mdspan/accessors/default.cc: New test. * testsuite/23_containers/mdspan/accessors/default_neg.cc: New test. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-06-12libstdc++: Uglify __mapping_alike template parameter and fix test and typo ↵Tomasz Kamiński1-11/+11
in comment. When the static assert was generated from instantiations of default member initializer of class B, the error was not generated for B<1, std::layout_left, std::layout_left> case, only when -D_GLIBCXX_DEBUG was set. Changing B calls to functions fixes that. We also replace class with typename in template head of layout_right::mapping constructors. libstdc++-v3/ChangeLog: * include/std/mdspan (__mdspan::__mapping_alike): Rename template parameter from M to _M_p. (layout_right::mapping): Replace class with typename in template head. (layout_stride::mapping): Fix typo in comment. * testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc: Changed B to function. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Make layout_left(layout_stride) noexcept.Luc Grosheintz1-1/+2
[mdspan.layout.left.cons] of N4950 states that this ctor is not noexcept. Since, all other ctors of layout_left, layout_right or layout_stride are noexcept, the choice was made, based on [res.on.exception.handling], to make this ctor noexcept. Two other major standard library implementations make the same choice. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_left): Strengthen the exception guarantees of layout_left::mapping(layout_stride::mapping). * testsuite/23_containers/mdspan/layouts/ctors.cc: Simplify tests to reflect the change. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Implement layout_stride from mdspan.Luc Grosheintz1-1/+248
Implements the remaining parts of layout_left and layout_right; and all of layout_stride. The implementation of layout_stride::mapping::is_exhaustive applies the following change to the standard: 4266. layout_stride::mapping should treat empty mappings as exhaustive https://cplusplus.github.io/LWG/issue4266 The preconditions for layout_stride(extents, strides) are not checked. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_stride): New class. * src/c++23/std.cc.in: Add layout_stride. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Implement layout_right from mdspan.Luc Grosheintz1-1/+152
Implement the parts of layout_left that depend on layout_right; and the parts of layout_right that don't depend on layout_stride. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_right): New class. * src/c++23/std.cc.in: Add layout_right. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Implement layout_left from mdspan.Luc Grosheintz1-1/+302
Implements the parts of layout_left that don't depend on any of the other layouts. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_left): New class. * src/c++23/std.cc.in: Add layout_left. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Improve naming, whitespace and silence warnings for extents.Luc Grosheintz1-12/+12
libstdc++-v3/ChangeLog: * include/std/mdspan(__mdspan::_ExtentsStorage): Change name of private member _M_dynamic_extens to _M_dyn_exts. (extents): Change name of private member from _M_dynamic_extents to _M_exts. Fix two instances of whitespace errors. * testsuite/23_containers/mdspan/extents/ctor_default.cc: Fix integer comparison with cmp_equal. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-05-27libstdc++: Fix bug in default ctor of extents.Luc Grosheintz1-1/+1
The array that stores the dynamic extents used to be default initialized. The standard requires value intialization. This commit fixes the bug and adds a test. libstdc++-v3/ChangeLog: * include/std/mdspan: Value initialize the array storing the dynamic extents. * testsuite/23_containers/mdspan/extents/ctor_default.cc: New test. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-05-15libstdc++: Fix class mandate for extents.Luc Grosheintz1-2/+3
The standard states that the IndexType must be a signed or unsigned integer. This mandate was implemented using `std::is_integral_v`. Which also includes (among others) char and bool, which neither signed nor unsigned integers. libstdc++-v3/ChangeLog: * include/std/mdspan: Implement the mandate for extents as signed or unsigned integer and not any interal type. Remove leading underscores from names in static_assert message. * testsuite/23_containers/mdspan/extents/class_mandates_neg.cc: Check that extents<char,...> and extents<bool,...> are invalid. Adjust dg-prune-output pattern. * testsuite/23_containers/mdspan/extents/misc.cc: Update tests to avoid `char` and `bool` as IndexType. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-05-07libstdc++: Implement std::extents [PR107761].Luc Grosheintz1-0/+261
This implements std::extents from <mdspan> according to N4950 and contains partial progress towards PR107761. If an extent changes its type, there's a precondition in the standard, that the value is representable in the target integer type. This precondition is not checked at runtime. The precondition for 'extents::{static_,}extent' is that '__r < rank()'. For extents<T> this precondition is always violated and results in calling __builtin_trap. For all other specializations it's checked via __glibcxx_assert. PR libstdc++/107761 libstdc++-v3/ChangeLog: * include/std/mdspan (extents): New class. * src/c++23/std.cc.in: Add 'using std::extents'. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-05-07libstdc++: Add header mdspan to the build-system.Luc Grosheintz1-0/+48
Creates a nearly empty header mdspan and adds it to the build-system and Doxygen config file. libstdc++-v3/ChangeLog: * doc/doxygen/user.cfg.in: Add <mdspan>. * include/Makefile.am: Ditto. * include/Makefile.in: Ditto. * include/precompiled/stdc++.h: Ditto. * include/std/mdspan: New file. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>