• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //   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 
21 #include "test_macros.h"
22 
main()23 int main()
24 {
25     {
26     std::chrono::seconds s1(3);
27     std::chrono::seconds s2(5);
28     std::chrono::seconds r = s1 + s2;
29     assert(r.count() == 8);
30     }
31     {
32     std::chrono::seconds s1(3);
33     std::chrono::microseconds s2(5);
34     std::chrono::microseconds r = s1 + s2;
35     assert(r.count() == 3000005);
36     }
37     {
38     std::chrono::duration<int, std::ratio<2, 3> > s1(3);
39     std::chrono::duration<int, std::ratio<3, 5> > s2(5);
40     std::chrono::duration<int, std::ratio<1, 15> > r = s1 + s2;
41     assert(r.count() == 75);
42     }
43     {
44     std::chrono::duration<int, std::ratio<2, 3> > s1(3);
45     std::chrono::duration<double, std::ratio<3, 5> > s2(5);
46     std::chrono::duration<double, std::ratio<1, 15> > r = s1 + s2;
47     assert(r.count() == 75);
48     }
49 #if TEST_STD_VER >= 11
50     {
51     constexpr std::chrono::seconds s1(3);
52     constexpr std::chrono::seconds s2(5);
53     constexpr std::chrono::seconds r = s1 + s2;
54     static_assert(r.count() == 8, "");
55     }
56     {
57     constexpr std::chrono::seconds s1(3);
58     constexpr std::chrono::microseconds s2(5);
59     constexpr std::chrono::microseconds r = s1 + s2;
60     static_assert(r.count() == 3000005, "");
61     }
62     {
63     constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3);
64     constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(5);
65     constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 + s2;
66     static_assert(r.count() == 75, "");
67     }
68     {
69     constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3);
70     constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(5);
71     constexpr std::chrono::duration<double, std::ratio<1, 15> > r = s1 + s2;
72     static_assert(r.count() == 75, "");
73     }
74 #endif
75 }
76