1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <chrono>
11
12 // duration
13
14 // template <class Rep1, class Period1, class Rep2, class Period2>
15 // constexpr
16 // typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
17 // operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
18
19 #include <chrono>
20 #include <cassert>
21
22 #include "test_macros.h"
23
main()24 int main()
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