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