mirror of git://gcc.gnu.org/git/gcc.git
libstdc++: Implement submdspan_mapping for layout_right. [PR110352]
Adds submdspan_mapping for layout_right as described in P3663. PR libstdc++/110352 libstdc++-v3/ChangeLog: * include/std/mdspan (__mdspan::_SubMdspanMapping<_LayoutSide::__right>): Define. (layout_right::mapping::submdspan_mapping): New friend function. * testsuite/23_containers/mdspan/submdspan/selections/right.cc: Instantiate tests for layout_right. * testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc: Ditto. * testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc: Ditto. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
This commit is contained in:
parent
ead579d3c5
commit
c1c5ada671
|
|
@ -1303,6 +1303,38 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
{ return __mdspan::__is_block(__slice_kinds, __sub_rank); }
|
{ return __mdspan::__is_block(__slice_kinds, __sub_rank); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct _SubMdspanMapping<_LayoutSide::__right>
|
||||||
|
{
|
||||||
|
using _Layout = layout_right;
|
||||||
|
template<size_t _Pad> using _PaddedLayout = layout_right_padded<_Pad>;
|
||||||
|
|
||||||
|
template<typename _Mapping, size_t _Us>
|
||||||
|
static consteval size_t
|
||||||
|
_S_pad()
|
||||||
|
{
|
||||||
|
using _Extents = typename _Mapping::extents_type;
|
||||||
|
constexpr auto __rank = _Extents::rank();
|
||||||
|
constexpr auto __sta_exts
|
||||||
|
= __mdspan::__static_extents<_Extents>(_Us + 1, __rank);
|
||||||
|
if constexpr (!__mdspan::__all_static(__sta_exts))
|
||||||
|
return dynamic_extent;
|
||||||
|
else
|
||||||
|
return __fwd_prod(__sta_exts);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t _Nm>
|
||||||
|
static consteval bool
|
||||||
|
_S_is_unpadded_submdspan(span<const _SliceKind, _Nm> __slice_kinds,
|
||||||
|
size_t __sub_rank)
|
||||||
|
{
|
||||||
|
auto __rev_slice_kinds = array<_SliceKind, _Nm>{};
|
||||||
|
for(size_t __i = 0; __i < _Nm; ++__i)
|
||||||
|
__rev_slice_kinds[__i] = __slice_kinds[_Nm - 1 - __i];
|
||||||
|
return __mdspan::__is_block(span(__rev_slice_kinds), __sub_rank);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename _Mapping>
|
template<typename _Mapping>
|
||||||
constexpr auto
|
constexpr auto
|
||||||
__submdspan_mapping_impl(const _Mapping& __mapping)
|
__submdspan_mapping_impl(const _Mapping& __mapping)
|
||||||
|
|
@ -1678,6 +1710,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
__glibcxx_assert(__mdspan::__is_representable_extents(_M_extents));
|
__glibcxx_assert(__mdspan::__is_representable_extents(_M_extents));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __glibcxx_submdspan
|
||||||
|
template<typename... _Slices>
|
||||||
|
requires (extents_type::rank() == sizeof...(_Slices))
|
||||||
|
friend constexpr auto
|
||||||
|
submdspan_mapping(const mapping& __mapping, _Slices... __slices)
|
||||||
|
{ return __mdspan::__submdspan_mapping_impl(__mapping, __slices...); }
|
||||||
|
#endif // __glibcxx_submdspan
|
||||||
|
|
||||||
[[no_unique_address]] extents_type _M_extents{};
|
[[no_unique_address]] extents_type _M_extents{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
// { dg-do run { target c++26 } }
|
||||||
|
#include "testcases.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
test_all<std::layout_right>();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -129,8 +129,14 @@ main()
|
||||||
test_layout_unpadded_return_types<std::layout_left>();
|
test_layout_unpadded_return_types<std::layout_left>();
|
||||||
static_assert(test_layout_unpadded_return_types<std::layout_left>());
|
static_assert(test_layout_unpadded_return_types<std::layout_left>());
|
||||||
|
|
||||||
|
test_layout_unpadded_return_types<std::layout_right>();
|
||||||
|
static_assert(test_layout_unpadded_return_types<std::layout_right>());
|
||||||
|
|
||||||
test_layout_unpadded_padding_value<std::layout_left>();
|
test_layout_unpadded_padding_value<std::layout_left>();
|
||||||
static_assert(test_layout_unpadded_padding_value<std::layout_left>());
|
static_assert(test_layout_unpadded_padding_value<std::layout_left>());
|
||||||
|
|
||||||
|
test_layout_unpadded_padding_value<std::layout_right>();
|
||||||
|
static_assert(test_layout_unpadded_padding_value<std::layout_right>());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ template<typename Layout>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static_assert(test_int_under<std::layout_left>()); // { dg-error "expansion of" }
|
static_assert(test_int_under<std::layout_left>()); // { dg-error "expansion of" }
|
||||||
|
static_assert(test_int_under<std::layout_right>()); // { dg-error "expansion of" }
|
||||||
|
|
||||||
template<typename Layout>
|
template<typename Layout>
|
||||||
constexpr bool
|
constexpr bool
|
||||||
|
|
@ -33,6 +34,7 @@ template<typename Layout>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static_assert(test_int_over<std::layout_left>()); // { dg-error "expansion of" }
|
static_assert(test_int_over<std::layout_left>()); // { dg-error "expansion of" }
|
||||||
|
static_assert(test_int_over<std::layout_right>()); // { dg-error "expansion of" }
|
||||||
|
|
||||||
template<typename Layout>
|
template<typename Layout>
|
||||||
constexpr bool
|
constexpr bool
|
||||||
|
|
@ -42,6 +44,7 @@ template<typename Layout>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static_assert(test_tuple_under<std::layout_left>()); // { dg-error "expansion of" }
|
static_assert(test_tuple_under<std::layout_left>()); // { dg-error "expansion of" }
|
||||||
|
static_assert(test_tuple_under<std::layout_right>()); // { dg-error "expansion of" }
|
||||||
|
|
||||||
template<typename Layout>
|
template<typename Layout>
|
||||||
constexpr bool
|
constexpr bool
|
||||||
|
|
@ -51,6 +54,7 @@ template<typename Layout>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static_assert(test_tuple_reversed<std::layout_left>()); // { dg-error "expansion of" }
|
static_assert(test_tuple_reversed<std::layout_left>()); // { dg-error "expansion of" }
|
||||||
|
static_assert(test_tuple_reversed<std::layout_right>()); // { dg-error "expansion of" }
|
||||||
|
|
||||||
template<typename Layout>
|
template<typename Layout>
|
||||||
constexpr bool
|
constexpr bool
|
||||||
|
|
@ -60,6 +64,7 @@ template<typename Layout>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static_assert(test_tuple_over<std::layout_left>()); // { dg-error "expansion of" }
|
static_assert(test_tuple_over<std::layout_left>()); // { dg-error "expansion of" }
|
||||||
|
static_assert(test_tuple_over<std::layout_right>()); // { dg-error "expansion of" }
|
||||||
|
|
||||||
template<typename Layout>
|
template<typename Layout>
|
||||||
constexpr bool
|
constexpr bool
|
||||||
|
|
@ -69,6 +74,7 @@ template<typename Layout>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static_assert(test_strided_slice_zero<std::layout_left>()); // { dg-error "expansion of" }
|
static_assert(test_strided_slice_zero<std::layout_left>()); // { dg-error "expansion of" }
|
||||||
|
static_assert(test_strided_slice_zero<std::layout_right>()); // { dg-error "expansion of" }
|
||||||
|
|
||||||
template<typename Layout>
|
template<typename Layout>
|
||||||
constexpr bool
|
constexpr bool
|
||||||
|
|
@ -78,6 +84,7 @@ template<typename Layout>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static_assert(test_strided_slice_offset_under<std::layout_left>()); // { dg-error "expansion of" }
|
static_assert(test_strided_slice_offset_under<std::layout_left>()); // { dg-error "expansion of" }
|
||||||
|
static_assert(test_strided_slice_offset_under<std::layout_right>()); // { dg-error "expansion of" }
|
||||||
|
|
||||||
template<typename Layout>
|
template<typename Layout>
|
||||||
constexpr bool
|
constexpr bool
|
||||||
|
|
@ -87,6 +94,7 @@ template<typename Layout>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static_assert(test_strided_slice_offset_over<std::layout_left>()); // { dg-error "expansion of" }
|
static_assert(test_strided_slice_offset_over<std::layout_left>()); // { dg-error "expansion of" }
|
||||||
|
static_assert(test_strided_slice_offset_over<std::layout_right>()); // { dg-error "expansion of" }
|
||||||
|
|
||||||
template<typename Layout>
|
template<typename Layout>
|
||||||
constexpr bool
|
constexpr bool
|
||||||
|
|
@ -96,6 +104,7 @@ template<typename Layout>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static_assert(test_strided_slice_extent_over<std::layout_left>()); // { dg-error "expansion of" }
|
static_assert(test_strided_slice_extent_over<std::layout_left>()); // { dg-error "expansion of" }
|
||||||
|
static_assert(test_strided_slice_extent_over<std::layout_right>()); // { dg-error "expansion of" }
|
||||||
|
|
||||||
// { dg-prune-output "static assertion failed" }
|
// { dg-prune-output "static assertion failed" }
|
||||||
// { dg-prune-output "__glibcxx_assert_fail" }
|
// { dg-prune-output "__glibcxx_assert_fail" }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue