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// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
15// operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
16
17#include <chrono>
18#include <cassert>
19#include <ratio>
20
21#include "test_macros.h"
22
23int main(int, char**)
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 return 0;
77}
78

source code of libcxx/test/std/time/time.duration/time.duration.nonmember/op_+.pass.cpp