mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
libstdc++: Add tests for layout_right.
Adds tests for layout_right and for the parts of layout_left that depend on layout_right. libstdc++-v3/ChangeLog: * testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc: Add tests for layout_right. * testsuite/23_containers/mdspan/layouts/ctors.cc: Add tests for layout_right and the interaction with layout_left. * testsuite/23_containers/mdspan/layouts/empty.cc: ditto. * testsuite/23_containers/mdspan/layouts/mapping.cc: ditto. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
This commit is contained in:
committed by
Tomasz Kamiński
parent
f40f96bcf2
commit
5b9edf2d37
@@ -30,7 +30,10 @@ template<size_t Count, typename Layout, typename OLayout>
|
||||
};
|
||||
|
||||
A<std::layout_left> a_left; // { dg-error "required from" }
|
||||
A<std::layout_right> a_right; // { dg-error "required from" }
|
||||
|
||||
B<1, std::layout_left, std::layout_left> b0; // { dg-error "required here" }
|
||||
|
||||
B<3, std::layout_right, std::layout_right> b2; // { dg-error "required here" }
|
||||
|
||||
// { dg-prune-output "must be representable as index_type" }
|
||||
|
||||
@@ -261,6 +261,66 @@ namespace from_same_layout
|
||||
}
|
||||
}
|
||||
|
||||
// ctor: mapping(layout_{right,left}::mapping<OExtents>)
|
||||
namespace from_left_or_right
|
||||
{
|
||||
template<typename SLayout, typename OLayout, typename SExtents,
|
||||
typename OExtents>
|
||||
constexpr void
|
||||
verify_ctor(OExtents oexts)
|
||||
{
|
||||
using SMapping = typename SLayout::mapping<SExtents>;
|
||||
using OMapping = typename OLayout::mapping<OExtents>;
|
||||
|
||||
constexpr bool expected = std::is_convertible_v<OExtents, SExtents>;
|
||||
if constexpr (expected)
|
||||
verify_nothrow_convertible<SMapping>(OMapping(oexts));
|
||||
else
|
||||
verify_nothrow_constructible<SMapping>(OMapping(oexts));
|
||||
}
|
||||
|
||||
template<typename SLayout, typename OLayout>
|
||||
constexpr bool
|
||||
test_ctor()
|
||||
{
|
||||
assert_not_constructible<
|
||||
typename SLayout::mapping<std::extents<int>>,
|
||||
typename OLayout::mapping<std::extents<int, 1>>>();
|
||||
|
||||
verify_ctor<OLayout, SLayout, std::extents<int>>(
|
||||
std::extents<unsigned int>{});
|
||||
|
||||
verify_ctor<OLayout, SLayout, std::extents<unsigned int>>(
|
||||
std::extents<int>{});
|
||||
|
||||
assert_not_constructible<
|
||||
typename SLayout::mapping<std::extents<int, 1>>,
|
||||
typename OLayout::mapping<std::extents<int>>>();
|
||||
|
||||
verify_ctor<OLayout, SLayout, std::extents<int, 1>>(
|
||||
std::extents<int, 1>{});
|
||||
|
||||
verify_ctor<OLayout, SLayout, std::extents<int, 1>>(
|
||||
std::extents<unsigned int, 1>{});
|
||||
|
||||
verify_ctor<OLayout, SLayout, std::extents<unsigned int, 1>>(
|
||||
std::extents<int, 1>{});
|
||||
|
||||
assert_not_constructible<
|
||||
typename SLayout::mapping<std::extents<int, 1, 2>>,
|
||||
typename OLayout::mapping<std::extents<int, 1, 2>>>();
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename SLayout, typename OLayout>
|
||||
constexpr void
|
||||
test_all()
|
||||
{
|
||||
test_ctor<SLayout, OLayout>();
|
||||
static_assert(test_ctor<SLayout, OLayout>());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Layout>
|
||||
constexpr void
|
||||
test_all()
|
||||
@@ -274,5 +334,9 @@ int
|
||||
main()
|
||||
{
|
||||
test_all<std::layout_left>();
|
||||
test_all<std::layout_right>();
|
||||
|
||||
from_left_or_right::test_all<std::layout_left, std::layout_right>();
|
||||
from_left_or_right::test_all<std::layout_right, std::layout_left>();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -108,5 +108,6 @@ int
|
||||
main()
|
||||
{
|
||||
static_assert(test_all<std::layout_left>());
|
||||
static_assert(test_all<std::layout_right>());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -293,6 +293,15 @@ template<>
|
||||
VERIFY(m.stride(1) == 3);
|
||||
}
|
||||
|
||||
template<>
|
||||
constexpr void
|
||||
test_stride_2d<std::layout_right>()
|
||||
{
|
||||
std::layout_right::mapping<std::extents<int, 3, 5>> m;
|
||||
VERIFY(m.stride(0) == 5);
|
||||
VERIFY(m.stride(1) == 1);
|
||||
}
|
||||
|
||||
template<typename Layout>
|
||||
constexpr void
|
||||
test_stride_3d();
|
||||
@@ -307,6 +316,16 @@ template<>
|
||||
VERIFY(m.stride(2) == 3*5);
|
||||
}
|
||||
|
||||
template<>
|
||||
constexpr void
|
||||
test_stride_3d<std::layout_right>()
|
||||
{
|
||||
std::layout_right::mapping m(std::dextents<int, 3>(3, 5, 7));
|
||||
VERIFY(m.stride(0) == 5*7);
|
||||
VERIFY(m.stride(1) == 7);
|
||||
VERIFY(m.stride(2) == 1);
|
||||
}
|
||||
|
||||
template<typename Layout>
|
||||
constexpr bool
|
||||
test_stride_all()
|
||||
@@ -381,24 +400,59 @@ template<typename M1, typename M2>
|
||||
{ m2 != m1 } -> std::same_as<bool>;
|
||||
};
|
||||
|
||||
template<typename Layout>
|
||||
constexpr bool
|
||||
template<typename SLayout, typename OLayout, bool Expected>
|
||||
constexpr void
|
||||
test_has_op_eq()
|
||||
{
|
||||
static_assert(has_op_eq<
|
||||
typename SLayout::mapping<std::extents<int>>,
|
||||
typename OLayout::mapping<std::extents<int>>> == Expected);
|
||||
|
||||
static_assert(!has_op_eq<
|
||||
typename Layout::mapping<std::extents<int, 1, 2>>,
|
||||
typename Layout::mapping<std::extents<int, 1>>>);
|
||||
typename SLayout::mapping<std::extents<int>>,
|
||||
typename OLayout::mapping<std::extents<int, 1>>>);
|
||||
|
||||
static_assert(has_op_eq<
|
||||
typename Layout::mapping<std::extents<int, 1>>,
|
||||
typename Layout::mapping<std::extents<int, 1>>>);
|
||||
typename SLayout::mapping<std::extents<int, 1>>,
|
||||
typename OLayout::mapping<std::extents<int, 1>>> == Expected);
|
||||
|
||||
static_assert(has_op_eq<
|
||||
typename Layout::mapping<std::extents<int, 1>>,
|
||||
typename Layout::mapping<std::extents<int, 2>>>);
|
||||
return true;
|
||||
typename SLayout::mapping<std::extents<int, 1>>,
|
||||
typename OLayout::mapping<std::extents<int, 2>>> == Expected);
|
||||
|
||||
static_assert(!has_op_eq<
|
||||
typename SLayout::mapping<std::extents<int, 1>>,
|
||||
typename OLayout::mapping<std::extents<int, 1, 2>>>);
|
||||
|
||||
static_assert(has_op_eq<
|
||||
typename SLayout::mapping<std::extents<int, 1, 2>>,
|
||||
typename OLayout::mapping<std::extents<int, 1, 2>>> == Expected);
|
||||
|
||||
static_assert(has_op_eq<
|
||||
typename SLayout::mapping<std::extents<int, 1, 2>>,
|
||||
typename OLayout::mapping<std::extents<int, 2, 2>>> == Expected);
|
||||
|
||||
static_assert(!has_op_eq<
|
||||
typename SLayout::mapping<std::extents<int, 1, 2>>,
|
||||
typename OLayout::mapping<std::extents<int, 1, 2, 3>>>);
|
||||
}
|
||||
|
||||
constexpr void
|
||||
test_has_op_eq_peculiar()
|
||||
{
|
||||
static_assert(has_op_eq<
|
||||
std::layout_right::mapping<std::extents<int>>,
|
||||
std::layout_left::mapping<std::extents<unsigned int>>>);
|
||||
|
||||
static_assert(has_op_eq<
|
||||
std::layout_right::mapping<std::extents<int, 1>>,
|
||||
std::layout_left::mapping<std::extents<int, dyn>>>);
|
||||
|
||||
static_assert(!has_op_eq<
|
||||
std::layout_right::mapping<std::extents<int, 1, 2>>,
|
||||
std::layout_left::mapping<std::extents<int, dyn, 2>>>);
|
||||
}
|
||||
|
||||
template<typename Layout>
|
||||
constexpr bool
|
||||
test_mapping_all()
|
||||
@@ -426,12 +480,16 @@ template<typename Layout>
|
||||
test_has_stride_0d<Layout>();
|
||||
test_has_stride_1d<Layout>();
|
||||
test_has_stride_2d<Layout>();
|
||||
test_has_op_eq<Layout>();
|
||||
test_has_op_eq<Layout, Layout, true>();
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test_all<std::layout_left>();
|
||||
test_all<std::layout_right>();
|
||||
|
||||
test_has_op_eq<std::layout_right, std::layout_left, false>();
|
||||
test_has_op_eq_peculiar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user