Skip to content

Commit 39934f7

Browse files
committed
Fix wrong concept usage in synth_three_way_result
1 parent c983c02 commit 39934f7

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

include/iris/compare.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct synth_three_way_result_impl
2222
using type = std::weak_ordering;
2323
};
2424

25-
template<class T, class U> requires std::three_way_comparable<T, U>
25+
template<class T, class U> requires std::three_way_comparable_with<T, U>
2626
struct synth_three_way_result_impl<T, U>
2727
{
2828
using type = std::invoke_result_t<std::compare_three_way, T const&, U const&>;
@@ -31,7 +31,7 @@ struct synth_three_way_result_impl<T, U>
3131
} // detail
3232

3333
template<class T, class U = T>
34-
using synth_three_way_result_t = detail::synth_three_way_result_impl<T, U>::type;
34+
using synth_three_way_result = detail::synth_three_way_result_impl<T, U>::type;
3535

3636
template<class T, class U = T>
3737
inline constexpr bool synth_three_way_noexcept =
@@ -45,7 +45,7 @@ inline constexpr bool synth_three_way_noexcept =
4545
>::value;
4646

4747
constexpr auto synth_three_way = []<class T, class U>(T const& t, U const& u) noexcept(synth_three_way_noexcept<T, U>)
48-
-> synth_three_way_result_t<T, U>
48+
-> synth_three_way_result<T, U>
4949
requires requires {
5050
{ t < u } -> req::boolean_testable;
5151
{ u < t } -> req::boolean_testable;

include/iris/indirect.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ constexpr bool operator==(indirect<T, Allocator> const& lhs, indirect<U, AA> con
402402

403403
template<class T, class Allocator, class U, class AA>
404404
constexpr auto operator<=>(indirect<T, Allocator> const& lhs, indirect<U, AA> const& rhs)
405-
noexcept(synth_three_way_noexcept<T, U>) -> synth_three_way_result_t<T, U>
405+
noexcept(noexcept(synth_three_way(*lhs, *rhs)))
406+
-> synth_three_way_result<T, U>
406407
{
407408
if (lhs.valueless_after_move() || rhs.valueless_after_move()) [[unlikely]] {
408409
return !lhs.valueless_after_move() <=> !rhs.valueless_after_move();
@@ -424,7 +425,8 @@ constexpr bool operator==(indirect<T, Allocator> const& lhs, U const& rhs)
424425

425426
template<class T, class Allocator, class U> requires (!is_ttp_specialization_of_v<U, indirect>)
426427
constexpr auto operator<=>(indirect<T, Allocator> const& lhs, U const& rhs)
427-
noexcept(synth_three_way_noexcept<T, U>) -> synth_three_way_result_t<T, U>
428+
noexcept(noexcept(synth_three_way(*lhs, rhs)))
429+
-> synth_three_way_result<T, U>
428430
{
429431
if (lhs.valueless_after_move()) [[unlikely]] {
430432
return std::strong_ordering::less;

include/iris/rvariant/recursive_wrapper.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ constexpr bool operator==(recursive_wrapper<T, TA> const& lhs, recursive_wrapper
178178
}
179179

180180
template<class T, class TA, class U, class UA>
181-
constexpr auto operator<=>(recursive_wrapper<T, TA> const& lhs, recursive_wrapper<U, UA> const& rhs) noexcept(synth_three_way_noexcept<T, U>)
182-
-> synth_three_way_result_t<T, U>
181+
constexpr auto operator<=>(recursive_wrapper<T, TA> const& lhs, recursive_wrapper<U, UA> const& rhs)
182+
noexcept(noexcept(synth_three_way(*lhs, *rhs)))
183+
-> synth_three_way_result<T, U>
183184
{
184185
if (lhs.valueless_after_move() || rhs.valueless_after_move()) [[unlikely]] {
185186
return !lhs.valueless_after_move() <=> !rhs.valueless_after_move();
@@ -200,7 +201,9 @@ constexpr bool operator==(recursive_wrapper<T, A> const& lhs, U const& rhs)
200201
}
201202

202203
template<class T, class A, class U>
203-
constexpr auto operator<=>(recursive_wrapper<T, A> const& lhs, U const& rhs) noexcept(synth_three_way_noexcept<T, U>) -> synth_three_way_result_t<T, U>
204+
constexpr auto operator<=>(recursive_wrapper<T, A> const& lhs, U const& rhs)
205+
noexcept(noexcept(synth_three_way(*lhs, rhs)))
206+
-> synth_three_way_result<T, U>
204207
{
205208
if (lhs.valueless_after_move()) [[unlikely]] {
206209
return std::strong_ordering::less;

test/rvariant/core_test.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
// SPDX-License-Identifier: MIT
1+
// SPDX-License-Identifier: MIT
22

33
#include <iris/type_traits.hpp>
44
#include <iris/requirements.hpp>
5+
#include <iris/compare.hpp>
56

67
#include <catch2/catch_test_macros.hpp>
78

9+
#include <concepts>
10+
811
namespace unit_test {
912

1013
TEST_CASE("pack_indexing")
@@ -406,4 +409,20 @@ TEST_CASE("Cpp17Swappable")
406409
}
407410
}
408411

412+
413+
TEST_CASE("synth_three_way")
414+
{
415+
STATIC_CHECK(std::same_as<iris::synth_three_way_result<int>, std::strong_ordering>);
416+
STATIC_CHECK(std::same_as<iris::synth_three_way_result<float>, std::partial_ordering>);
417+
418+
struct NoThreeWay
419+
{
420+
bool operator<(NoThreeWay const&) const { return false; }
421+
bool operator>(NoThreeWay const&) const { return false; }
422+
auto operator<=>(NoThreeWay const&) const = delete;
423+
};
424+
425+
STATIC_CHECK(std::same_as<iris::synth_three_way_result<NoThreeWay>, std::weak_ordering>);
426+
}
427+
409428
} // unit_test

0 commit comments

Comments
 (0)