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 Rep1, class Period1, class Rep2, class Period2>
16 // requires ThreeWayComparable<typename CT::rep>
17 // constexpr auto operator<=>(const duration<Rep1, Period1>& lhs,
18 // const duration<Rep2, Period2>& rhs);
24 #include "test_comparisons.h"
26 constexpr bool test() {
28 std::chrono::seconds
s1(3);
29 std::chrono::seconds
s2(3);
30 assert((s1
<=> s2
) == std::strong_ordering::equal
);
31 assert(testOrder(s1
, s2
, std::strong_ordering::equal
));
34 std::chrono::seconds
s1(3);
35 std::chrono::seconds
s2(4);
36 assert((s1
<=> s2
) == std::strong_ordering::less
);
37 assert(testOrder(s1
, s2
, std::strong_ordering::less
));
40 std::chrono::milliseconds
s1(3);
41 std::chrono::microseconds
s2(3000);
42 assert((s1
<=> s2
) == std::strong_ordering::equal
);
43 assert(testOrder(s1
, s2
, std::strong_ordering::equal
));
46 std::chrono::milliseconds
s1(3);
47 std::chrono::microseconds
s2(4000);
48 assert((s1
<=> s2
) == std::strong_ordering::less
);
49 assert(testOrder(s1
, s2
, std::strong_ordering::less
));
52 std::chrono::duration
<int, std::ratio
<2, 3>> s1(9);
53 std::chrono::duration
<int, std::ratio
<3, 5>> s2(10);
54 assert((s1
<=> s2
) == std::strong_ordering::equal
);
55 assert(testOrder(s1
, s2
, std::strong_ordering::equal
));
58 std::chrono::duration
<int, std::ratio
<2, 3>> s1(10);
59 std::chrono::duration
<int, std::ratio
<3, 5>> s2(9);
60 assert((s1
<=> s2
) == std::strong_ordering::greater
);
61 assert(testOrder(s1
, s2
, std::strong_ordering::greater
));
64 std::chrono::duration
<int, std::ratio
<2, 3>> s1(9);
65 std::chrono::duration
<double, std::ratio
<3, 5>> s2(10.1);
66 assert((s1
<=> s2
) == std::strong_ordering::less
);
67 assert(testOrder(s1
, s2
, std::strong_ordering::less
));
73 int main(int, char**) {
75 static_assert(test());