1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 // template <class Rep1, class Period1, class Rep2, class Period2>
14 // typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
15 // operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
21 #include "test_macros.h"
26 std::chrono::seconds
s1(3);
27 std::chrono::seconds
s2(5);
28 std::chrono::seconds r
= s1
+ s2
;
29 assert(r
.count() == 8);
32 std::chrono::seconds
s1(3);
33 std::chrono::microseconds
s2(5);
34 std::chrono::microseconds r
= s1
+ s2
;
35 assert(r
.count() == 3000005);
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);
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);
49 #if TEST_STD_VER >= 11
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, "");
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, "");
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, "");
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, "");