1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
15 // template<class Clock, class Duration1,
16 // three_way_comparable_with<Duration1> Duration2>
17 // constexpr auto operator<=>(const time_point<Clock, Duration1>& lhs,
18 // const time_point<Clock, Duration2>& rhs);
24 #include "test_comparisons.h"
26 constexpr void test_with_integral_ticks_value() {
27 using Clock
= std::chrono::system_clock
;
29 using Duration1
= std::chrono::milliseconds
;
30 using Duration2
= std::chrono::microseconds
;
31 using T1
= std::chrono::time_point
<Clock
, Duration1
>;
32 using T2
= std::chrono::time_point
<Clock
, Duration2
>;
37 assert((t1
<=> t2
) == std::strong_ordering::equal
);
38 assert(testOrder(t1
, t2
, std::strong_ordering::equal
));
43 assert((t1
<=> t2
) == std::strong_ordering::less
);
44 assert(testOrder(t1
, t2
, std::strong_ordering::less
));
48 T2
t2(Duration2(3000));
49 assert((t1
<=> t2
) == std::strong_ordering::equal
);
50 assert(testOrder(t1
, t2
, std::strong_ordering::equal
));
54 T2
t2(Duration2(3001));
55 assert((t1
<=> t2
) == std::strong_ordering::less
);
56 assert(testOrder(t1
, t2
, std::strong_ordering::less
));
57 assert((t2
<=> t1
) == std::strong_ordering::greater
);
58 assert(testOrder(t2
, t1
, std::strong_ordering::greater
));
62 constexpr void test_with_integral_ticks_value_and_custom_period_value() {
63 using Clock
= std::chrono::system_clock
;
65 using DInt30Hz
= std::chrono::duration
<int, std::ratio
<1, 30>>;
66 using DInt60Hz
= std::chrono::duration
<int, std::ratio
<1, 60>>;
68 using TIntR1
= std::chrono::time_point
<Clock
, DInt30Hz
>;
69 using TIntR2
= std::chrono::time_point
<Clock
, DInt60Hz
>;
72 TIntR1
t1(DInt30Hz(10));
73 TIntR2
t2(DInt60Hz(20));
74 assert((t1
<=> t2
) == std::strong_ordering::equal
);
75 assert(testOrder(t1
, t2
, std::strong_ordering::equal
));
78 TIntR1
t1(DInt30Hz(10));
79 TIntR2
t2(DInt60Hz(21));
80 assert((t1
<=> t2
) == std::strong_ordering::less
);
81 assert(testOrder(t1
, t2
, std::strong_ordering::less
));
84 TIntR1
t1(DInt30Hz(11));
85 TIntR2
t2(DInt60Hz(20));
86 assert((t1
<=> t2
) == std::strong_ordering::greater
);
87 assert(testOrder(t1
, t2
, std::strong_ordering::greater
));
91 constexpr void test_with_floating_point_ticks_value() {
92 using Clock
= std::chrono::system_clock
;
94 using DF30Hz
= std::chrono::duration
<double, std::ratio
<1, 30>>;
95 using DF60Hz
= std::chrono::duration
<double, std::ratio
<1, 60>>;
96 using F1
= std::chrono::time_point
<Clock
, DF30Hz
>;
97 using F2
= std::chrono::time_point
<Clock
, DF60Hz
>;
99 // No equality comparison test for floating point values.
104 assert((t1
<=> t2
) == std::weak_ordering::less
);
105 assert(testOrder(t1
, t2
, std::weak_ordering::less
));
110 assert((t1
<=> t2
) == std::weak_ordering::greater
);
111 assert(testOrder(t1
, t2
, std::weak_ordering::greater
));
115 constexpr bool test() {
116 test_with_integral_ticks_value();
117 test_with_integral_ticks_value_and_custom_period_value();
118 test_with_floating_point_ticks_value();
123 int main(int, char**) {
125 static_assert(test());