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 | // typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type |
16 | // operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
17 | |
18 | #include <chrono> |
19 | #include <cassert> |
20 | #include <ratio> |
21 | |
22 | #include "test_macros.h" |
23 | |
24 | int main(int, char**) |
25 | { |
26 | { |
27 | std::chrono::seconds s1(3); |
28 | std::chrono::seconds s2(5); |
29 | std::chrono::seconds r = s1 - s2; |
30 | assert(r.count() == -2); |
31 | } |
32 | { |
33 | std::chrono::seconds s1(3); |
34 | std::chrono::microseconds s2(5); |
35 | std::chrono::microseconds r = s1 - s2; |
36 | assert(r.count() == 2999995); |
37 | } |
38 | { |
39 | std::chrono::duration<int, std::ratio<2, 3> > s1(3); |
40 | std::chrono::duration<int, std::ratio<3, 5> > s2(5); |
41 | std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2; |
42 | assert(r.count() == -15); |
43 | } |
44 | { |
45 | std::chrono::duration<int, std::ratio<2, 3> > s1(3); |
46 | std::chrono::duration<double, std::ratio<3, 5> > s2(5); |
47 | std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2; |
48 | assert(r.count() == -15); |
49 | } |
50 | #if TEST_STD_VER >= 11 |
51 | { |
52 | constexpr std::chrono::seconds s1(3); |
53 | constexpr std::chrono::seconds s2(5); |
54 | constexpr std::chrono::seconds r = s1 - s2; |
55 | static_assert(r.count() == -2, "" ); |
56 | } |
57 | { |
58 | constexpr std::chrono::seconds s1(3); |
59 | constexpr std::chrono::microseconds s2(5); |
60 | constexpr std::chrono::microseconds r = s1 - s2; |
61 | static_assert(r.count() == 2999995, "" ); |
62 | } |
63 | { |
64 | constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); |
65 | constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(5); |
66 | constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2; |
67 | static_assert(r.count() == -15, "" ); |
68 | } |
69 | { |
70 | constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); |
71 | constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(5); |
72 | constexpr std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2; |
73 | static_assert(r.count() == -15, "" ); |
74 | } |
75 | #endif |
76 | |
77 | return 0; |
78 | } |
79 | |