Skip to content

Commit

Permalink
Fix feature testing and add missing guards on other operator != (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau authored Sep 5, 2024
1 parent 75bcbeb commit 5fc2cb7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/ddc/aligned_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ constexpr bool operator==(AlignedAllocator<T, NT> const&, AlignedAllocator<U, NU
return std::is_same_v<AlignedAllocator<T, NT>, AlignedAllocator<U, NU>>;
}

#if !defined(__cpp_impl_three_way_comparison)
// In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
template <class T, std::size_t NT, class U, std::size_t NU>
constexpr bool operator!=(AlignedAllocator<T, NT> const&, AlignedAllocator<U, NU> const&) noexcept
{
return !std::is_same_v<AlignedAllocator<T, NT>, AlignedAllocator<U, NU>>;
}
#endif

} // namespace ddc
3 changes: 3 additions & 0 deletions include/ddc/detail/tagged_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,15 @@ class TaggedVector : public TaggedVectorConversionOperators<TaggedVector<Element
return ((m_values[type_seq_rank_v<Tags, tags_seq>] == rhs.template get<Tags>()) && ...);
}

#if !defined(__cpp_impl_three_way_comparison)
// In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
template <class OElementType, class... OTags>
KOKKOS_FUNCTION constexpr bool operator!=(
TaggedVector<OElementType, OTags...> const& rhs) const noexcept
{
return !(*this == rhs);
}
#endif

template <class QueryTag>
KOKKOS_FUNCTION constexpr ElementType& get() noexcept
Expand Down
13 changes: 7 additions & 6 deletions include/ddc/discrete_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ class DiscreteDomain
return m_element_begin == other.m_element_begin && m_element_end == other.m_element_end;
}

#if __cplusplus <= 201703L
// Shall not be necessary anymore in C++20
// `a!=b` shall be translated by the compiler to `!(a==b)`
#if !defined(__cpp_impl_three_way_comparison)
// In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
template <class... ODims>
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomain<ODims...> const& other) const
{
Expand Down Expand Up @@ -293,9 +292,8 @@ class DiscreteDomain<>
return true;
}

#if __cplusplus <= 201703L
// Shall not be necessary anymore in C++20
// `a!=b` shall be translated by the compiler to `!(a==b)`
#if !defined(__cpp_impl_three_way_comparison)
// In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomain const& other) const
{
return !(*this == other);
Expand Down Expand Up @@ -599,12 +597,15 @@ struct DiscreteDomainIterator
return xx.m_value == yy.m_value;
}

#if !defined(__cpp_impl_three_way_comparison)
// In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
friend KOKKOS_FUNCTION constexpr bool operator!=(
DiscreteDomainIterator const& xx,
DiscreteDomainIterator const& yy)
{
return xx.m_value != yy.m_value;
}
#endif

friend KOKKOS_FUNCTION constexpr bool operator<(
DiscreteDomainIterator const& xx,
Expand Down
3 changes: 3 additions & 0 deletions include/ddc/discrete_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,16 @@ KOKKOS_FUNCTION constexpr bool operator==(
return ((lhs.template uid<Tags>() == rhs.template uid<Tags>()) && ...);
}

#if !defined(__cpp_impl_three_way_comparison)
// In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
template <class... Tags, class... OTags>
KOKKOS_FUNCTION constexpr bool operator!=(
DiscreteElement<Tags...> const& lhs,
DiscreteElement<OTags...> const& rhs) noexcept
{
return !(lhs == rhs);
}
#endif

template <class Tag>
KOKKOS_FUNCTION constexpr bool operator<(
Expand Down
3 changes: 3 additions & 0 deletions include/ddc/discrete_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,14 @@ class DiscreteVector : public detail::DiscreteVectorConversionOperators<Discrete
return ((m_values[type_seq_rank_v<Tags, tags_seq>] == rhs.template get<Tags>()) && ...);
}

#if !defined(__cpp_impl_three_way_comparison)
// In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
template <class... OTags>
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector<OTags...> const& rhs) const noexcept
{
return !(*this == rhs);
}
#endif

template <class QueryTag>
KOKKOS_FUNCTION constexpr DiscreteVectorElement& get() noexcept
Expand Down
3 changes: 3 additions & 0 deletions include/ddc/kokkos_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ constexpr bool operator==(KokkosAllocator<T, MST> const&, KokkosAllocator<U, MSU
return std::is_same_v<KokkosAllocator<T, MST>, KokkosAllocator<U, MSU>>;
}

#if !defined(__cpp_impl_three_way_comparison)
// In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
template <class T, class MST, class U, class MSU>
constexpr bool operator!=(KokkosAllocator<T, MST> const&, KokkosAllocator<U, MSU> const&) noexcept
{
return !std::is_same_v<KokkosAllocator<T, MST>, KokkosAllocator<U, MSU>>;
}
#endif

template <class T>
using DeviceAllocator = KokkosAllocator<T, Kokkos::DefaultExecutionSpace::memory_space>;
Expand Down

0 comments on commit 5fc2cb7

Please sign in to comment.