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#include <chrono>
24#include <cassert>
25#include <ratio>
26
27#include "test_macros.h"
28
29int main(int, char**)
30{
31 {
32 std::chrono::seconds s1(3);
33 std::chrono::seconds s2(3);
34 assert(s1 == s2);
35 assert(!(s1 != s2));
36 }
37 {
38 std::chrono::seconds s1(3);
39 std::chrono::seconds s2(4);
40 assert(!(s1 == s2));
41 assert(s1 != s2);
42 }
43 {
44 std::chrono::milliseconds s1(3);
45 std::chrono::microseconds s2(3000);
46 assert(s1 == s2);
47 assert(!(s1 != s2));
48 }
49 {
50 std::chrono::milliseconds s1(3);
51 std::chrono::microseconds s2(4000);
52 assert(!(s1 == s2));
53 assert(s1 != s2);
54 }
55 {
56 std::chrono::duration<int, std::ratio<2, 3> > s1(9);
57 std::chrono::duration<int, std::ratio<3, 5> > s2(10);
58 assert(s1 == s2);
59 assert(!(s1 != s2));
60 }
61 {
62 std::chrono::duration<int, std::ratio<2, 3> > s1(10);
63 std::chrono::duration<int, std::ratio<3, 5> > s2(9);
64 assert(!(s1 == s2));
65 assert(s1 != s2);
66 }
67 {
68 std::chrono::duration<int, std::ratio<2, 3> > s1(9);
69 std::chrono::duration<double, std::ratio<3, 5> > s2(10);
70 assert(s1 == s2);
71 assert(!(s1 != s2));
72 }
73#if TEST_STD_VER >= 11
74 {
75 constexpr std::chrono::seconds s1(3);
76 constexpr std::chrono::seconds s2(3);
77 static_assert(s1 == s2, "");
78 static_assert(!(s1 != s2), "");
79 }
80 {
81 constexpr std::chrono::seconds s1(3);
82 constexpr std::chrono::seconds s2(4);
83 static_assert(!(s1 == s2), "");
84 static_assert(s1 != s2, "");
85 }
86 {
87 constexpr std::chrono::milliseconds s1(3);
88 constexpr std::chrono::microseconds s2(3000);
89 static_assert(s1 == s2, "");
90 static_assert(!(s1 != s2), "");
91 }
92 {
93 constexpr std::chrono::milliseconds s1(3);
94 constexpr std::chrono::microseconds s2(4000);
95 static_assert(!(s1 == s2), "");
96 static_assert(s1 != s2, "");
97 }
98 {
99 constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9);
100 constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(10);
101 static_assert(s1 == s2, "");
102 static_assert(!(s1 != s2), "");
103 }
104 {
105 constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(10);
106 constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(9);
107 static_assert(!(s1 == s2), "");
108 static_assert(s1 != s2, "");
109 }
110 {
111 constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9);
112 constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(10);
113 static_assert(s1 == s2, "");
114 static_assert(!(s1 != s2), "");
115 }
116#endif
117
118 return 0;
119}
120

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