Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix equality operator of layout_stride, after #196 #228

Merged
merged 1 commit into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/experimental/__p0009_bits/layout_stride.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ struct layout_stride {
template <class OtherExtents>
MDSPAN_INLINE_FUNCTION
static constexpr bool _eq_impl(mapping const& self, mapping<OtherExtents> const& other) noexcept {
return _MDSPAN_FOLD_AND((self.stride(Idxs) == other.stride(Idxs)) /* && ... */);
return _MDSPAN_FOLD_AND((self.stride(Idxs) == other.stride(Idxs)) /* && ... */)
&& _MDSPAN_FOLD_AND((self.extents().extent(Idxs) == other.extents().extent(Idxs)) /* || ... */);
}
template <class OtherExtents>
MDSPAN_INLINE_FUNCTION
static constexpr bool _not_eq_impl(mapping const& self, mapping<OtherExtents> const& other) noexcept {
return _MDSPAN_FOLD_OR((self.stride(Idxs) != other.stride(Idxs)) /* || ... */);
return _MDSPAN_FOLD_OR((self.stride(Idxs) != other.stride(Idxs)) /* || ... */)
|| _MDSPAN_FOLD_OR((self.extents().extent(Idxs) != other.extents().extent(Idxs)) /* || ... */);
}

template <class... Integral>
Expand Down
46 changes: 46 additions & 0 deletions tests/test_layout_stride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,52 @@ TEST(TestLayoutStrideListInitialization, test_list_initialization) {
ASSERT_FALSE(m.is_exhaustive());
}

template <class> struct TestLayoutEquality;
template <class Mapping, size_t... DynamicSizes, class Mapping2, size_t... DynamicSizes2, class Equality>
struct TestLayoutEquality<std::tuple<
Mapping,
std::integer_sequence<size_t, DynamicSizes...>,
Mapping2,
std::integer_sequence<size_t, DynamicSizes2...>,
Equality
>> : public ::testing::Test {
using mapping_type1 = Mapping;
using mapping_type2 = Mapping2;
using extents_type1 = std::remove_reference_t<decltype(std::declval<mapping_type1>().extents())>;
using extents_type2 = std::remove_reference_t<decltype(std::declval<mapping_type2>().extents())>;
mapping_type1 map1 = { extents_type1{}, std::array<size_t, sizeof...(DynamicSizes)>{ DynamicSizes... } };
mapping_type2 map2 = { extents_type2{}, std::array<size_t, sizeof...(DynamicSizes2)>{ DynamicSizes2... } };
bool equal = Equality::value;
};

template <class E1, class S1, class E2, class S2, class Equal>
using test_stride_equality = std::tuple<
typename stdex::layout_stride::template mapping<E1>, S1,
typename stdex::layout_stride::template mapping<E2>, S2,
Equal
>;
template <size_t... Ds>
using _sizes = std::integer_sequence<size_t, Ds...>;
template <size_t... Ds>
using _exts = stdex::extents<size_t,Ds...>;

template <template <class, class, class, class, class> class _test_case_type>
using equality_test_types =
::testing::Types<
_test_case_type<_exts<16, 32>, _sizes<1, 16>, _exts<16, 32>, _sizes<1, 16>, std:: true_type>,
_test_case_type<_exts<16, 32>, _sizes<1, 16>, _exts<16, 32>, _sizes<1, 17>, std::false_type>,
_test_case_type<_exts<16, 32>, _sizes<1, 16>, _exts<16, 64>, _sizes<1, 16>, std::false_type>,
_test_case_type<_exts<16, 32>, _sizes<1, 16>, _exts<16, 64>, _sizes<1, 17>, std::false_type>
>;

using layout_stride_equality_test_types = equality_test_types<test_stride_equality>;

TYPED_TEST_SUITE(TestLayoutEquality, layout_stride_equality_test_types);

TYPED_TEST(TestLayoutEquality, equality_op) {
ASSERT_EQ(this->map1 == this->map2, this->equal);
}

// This fails on GCC 9.2 and others
#if defined(_MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION)
TEST(TestLayoutStrideCTAD, test_ctad) {
Expand Down