Skip to content

Remove useless != and fix size related checks on comparisons operators #64

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

Merged
merged 1 commit into from
May 15, 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
28 changes: 10 additions & 18 deletions include/kumi/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,15 +660,16 @@ namespace kumi
(std::make_index_sequence<sizeof...(Ts)>());
return *this;
}
template<sized_product_type<sizeof...(Ts)> Other>
template<product_type Other>
friend constexpr auto operator==(tuple const &self, Other const &other) noexcept
requires( (sizeof...(Ts) != 0 ) && equality_comparable<tuple,Other> )
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>)
&& equality_comparable<tuple,Other>
)
{
return [&]<std::size_t... I>(std::index_sequence<I...>)
{
return ((get<I>(self) == get<I>(other)) && ...);
}
(std::make_index_sequence<sizeof...(Ts)>());
} (std::make_index_sequence<sizeof...(Ts)>());
}
#if !defined(KUMI_DOXYGEN_INVOKED)
template<sized_product_type<0> Other>
Expand All @@ -677,21 +678,9 @@ namespace kumi
return true;
}
#endif
template<sized_product_type<sizeof...(Ts)> Other>
friend constexpr auto operator!=(tuple const &self, Other const &other) noexcept
requires( (sizeof...(Ts) != 0 ) && equality_comparable<tuple,Other> )
{
return !(self == other);
}
#if !defined(KUMI_DOXYGEN_INVOKED)
template<sized_product_type<0> Other>
friend constexpr auto operator!=(tuple const&, Other const &) noexcept
{
return false;
}
#endif
template<sized_product_type<sizeof...(Ts)> Other>
template<product_type Other>
friend constexpr auto operator<(tuple const &lhs, Other const &rhs) noexcept
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>) )
{
auto res = get<0>(lhs) < get<0>(rhs);
auto const order = [&]<typename Index>(Index i)
Expand All @@ -709,16 +698,19 @@ namespace kumi
}
template<product_type Other>
friend constexpr auto operator<=(tuple const &lhs, Other const &rhs) noexcept
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>) )
{
return !(rhs < lhs);
}
template<product_type Other>
friend constexpr auto operator>(tuple const &lhs, Other const &rhs) noexcept
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>) )
{
return rhs < lhs;
}
template<product_type Other>
friend constexpr auto operator>=(tuple const &lhs, Other const &rhs) noexcept
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>) )
{
return !(lhs < rhs);
}
Expand Down
33 changes: 10 additions & 23 deletions src/kumi/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,16 @@ namespace kumi
/// @ingroup tuple
/// @related kumi::tuple
/// @brief Compares a tuple with an other kumi::product_type for equality
template<sized_product_type<sizeof...(Ts)> Other>
template<product_type Other>
friend constexpr auto operator==(tuple const &self, Other const &other) noexcept
requires( (sizeof...(Ts) != 0 ) && equality_comparable<tuple,Other> )
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>)
&& equality_comparable<tuple,Other>
)
{
return [&]<std::size_t... I>(std::index_sequence<I...>)
{
return ((get<I>(self) == get<I>(other)) && ...);
}
(std::make_index_sequence<sizeof...(Ts)>());
} (std::make_index_sequence<sizeof...(Ts)>());
}

#if !defined(KUMI_DOXYGEN_INVOKED)
Expand All @@ -197,29 +198,12 @@ namespace kumi
}
#endif

/// @ingroup tuple
/// @related kumi::tuple
/// @brief Compares a tuple with an other kumi::product_type for inequality
template<sized_product_type<sizeof...(Ts)> Other>
friend constexpr auto operator!=(tuple const &self, Other const &other) noexcept
requires( (sizeof...(Ts) != 0 ) && equality_comparable<tuple,Other> )
{
return !(self == other);
}

#if !defined(KUMI_DOXYGEN_INVOKED)
template<sized_product_type<0> Other>
friend constexpr auto operator!=(tuple const&, Other const &) noexcept
{
return false;
}
#endif

/// @ingroup tuple
/// @related kumi::tuple
/// @brief Compares tuple and product type value for lexicographical is less relation
template<sized_product_type<sizeof...(Ts)> Other>
template<product_type Other>
friend constexpr auto operator<(tuple const &lhs, Other const &rhs) noexcept
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>) )
{
// lexicographical order is defined as
// (v0 < w0) || ... andnot(wi < vi, vi+1 < wi+1) ... || andnot(wn-1 < vn-1, vn < wn);
Expand All @@ -246,6 +230,7 @@ namespace kumi
/// @brief Compares tuple and product type value for lexicographical is less or equal relation
template<product_type Other>
friend constexpr auto operator<=(tuple const &lhs, Other const &rhs) noexcept
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>) )
{
return !(rhs < lhs);
}
Expand All @@ -255,6 +240,7 @@ namespace kumi
/// @brief Compares tuple and product type value for lexicographical is greater relation
template<product_type Other>
friend constexpr auto operator>(tuple const &lhs, Other const &rhs) noexcept
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>) )
{
return rhs < lhs;
}
Expand All @@ -264,6 +250,7 @@ namespace kumi
/// @brief Compares tuple and product type value for lexicographical is greater relation relation
template<product_type Other>
friend constexpr auto operator>=(tuple const &lhs, Other const &rhs) noexcept
requires( (sizeof...(Ts) != 0 ) && (sizeof...(Ts) == size_v<Other>) )
{
return !(lhs < rhs);
}
Expand Down