1//===----------------------------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9// <chrono>
10
11// duration
12
13// template <class Rep1, class Period1, class Rep2, class Period2>
14// constexpr
15// bool
16// operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
17
18// template <class Rep1, class Period1, class Rep2, class Period2>
19// constexpr
20// bool
21// operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
22
23// template <class Rep1, class Period1, class Rep2, class Period2>
24// constexpr
25// bool
26// operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
27
28// template <class Rep1, class Period1, class Rep2, class Period2>
29// constexpr
30// bool
31// operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
32
33#include <chrono>
34#include <cassert>
35#include <ratio>
36
37#include "test_macros.h"
38
39int main(int, char**)
40{
41 {
42 std::chrono::seconds s1(3);
43 std::chrono::seconds s2(3);
44 assert(!(s1 < s2));
45 assert(!(s1 > s2));
46 assert( (s1 <= s2));
47 assert( (s1 >= s2));
48 }
49 {
50 std::chrono::seconds s1(3);
51 std::chrono::seconds s2(4);
52 assert( (s1 < s2));
53 assert(!(s1 > s2));
54 assert( (s1 <= s2));
55 assert(!(s1 >= s2));
56 }
57 {
58 std::chrono::milliseconds s1(3);
59 std::chrono::microseconds s2(3000);
60 assert(!(s1 < s2));
61 assert(!(s1 > s2));
62 assert( (s1 <= s2));
63 assert( (s1 >= s2));
64 }
65 {
66 std::chrono::milliseconds s1(3);
67 std::chrono::microseconds s2(4000);
68 assert( (s1 < s2));
69 assert(!(s1 > s2));
70 assert( (s1 <= s2));
71 assert(!(s1 >= s2));
72 }
73 {
74 std::chrono::duration<int, std::ratio<2, 3> > s1(9);
75 std::chrono::duration<int, std::ratio<3, 5> > s2(10);
76 assert(!(s1 < s2));
77 assert(!(s1 > s2));
78 assert( (s1 <= s2));
79 assert( (s1 >= s2));
80 }
81 {
82 std::chrono::duration<int, std::ratio<2, 3> > s1(10);
83 std::chrono::duration<int, std::ratio<3, 5> > s2(9);
84 assert(!(s1 < s2));
85 assert( (s1 > s2));
86 assert(!(s1 <= s2));
87 assert( (s1 >= s2));
88 }
89 {
90 std::chrono::duration<int, std::ratio<2, 3> > s1(9);
91 std::chrono::duration<double, std::ratio<3, 5> > s2(10);
92 assert(!(s1 < s2));
93 assert(!(s1 > s2));
94 assert( (s1 <= s2));
95 assert( (s1 >= s2));
96 }
97#if TEST_STD_VER >= 11
98 {
99 constexpr std::chrono::seconds s1(3);
100 constexpr std::chrono::seconds s2(3);
101 static_assert(!(s1 < s2), "");
102 static_assert(!(s1 > s2), "");
103 static_assert( (s1 <= s2), "");
104 static_assert( (s1 >= s2), "");
105 }
106 {
107 constexpr std::chrono::seconds s1(3);
108 constexpr std::chrono::seconds s2(4);
109 static_assert( (s1 < s2), "");
110 static_assert(!(s1 > s2), "");
111 static_assert( (s1 <= s2), "");
112 static_assert(!(s1 >= s2), "");
113 }
114 {
115 constexpr std::chrono::milliseconds s1(3);
116 constexpr std::chrono::microseconds s2(3000);
117 static_assert(!(s1 < s2), "");
118 static_assert(!(s1 > s2), "");
119 static_assert( (s1 <= s2), "");
120 static_assert( (s1 >= s2), "");
121 }
122 {
123 constexpr std::chrono::milliseconds s1(3);
124 constexpr std::chrono::microseconds s2(4000);
125 static_assert( (s1 < s2), "");
126 static_assert(!(s1 > s2), "");
127 static_assert( (s1 <= s2), "");
128 static_assert(!(s1 >= s2), "");
129 }
130 {
131 constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9);
132 constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(10);
133 static_assert(!(s1 < s2), "");
134 static_assert(!(s1 > s2), "");
135 static_assert( (s1 <= s2), "");
136 static_assert( (s1 >= s2), "");
137 }
138 {
139 constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(10);
140 constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(9);
141 static_assert(!(s1 < s2), "");
142 static_assert( (s1 > s2), "");
143 static_assert(!(s1 <= s2), "");
144 static_assert( (s1 >= s2), "");
145 }
146 {
147 constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9);
148 constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(10);
149 static_assert(!(s1 < s2), "");
150 static_assert(!(s1 > s2), "");
151 static_assert( (s1 <= s2), "");
152 static_assert( (s1 >= s2), "");
153 }
154#endif
155
156 return 0;
157}
158

source code of libcxx/test/std/time/time.duration/time.duration.comparisons/op_less.pass.cpp