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 // template <class Clock, class Duration1, class Duration2>
12 // struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>
13 // {
14 //     typedef chrono::time_point<Clock, typename common_type<Duration1, Duration2>::type> type;
15 // };
16 
17 #include <chrono>
18 
19 #include "test_macros.h"
20 
21 template <class D1, class D2, class De>
22 void
test()23 test()
24 {
25     typedef std::chrono::system_clock C;
26     typedef std::chrono::time_point<C, D1> T1;
27     typedef std::chrono::time_point<C, D2> T2;
28     typedef std::chrono::time_point<C, De> Te;
29     typedef typename std::common_type<T1, T2>::type Tc;
30     static_assert((std::is_same<Tc, Te>::value), "");
31 }
32 
main(int,char **)33 int main(int, char**)
34 {
35     test<std::chrono::duration<int, std::ratio<1, 100> >,
36          std::chrono::duration<long, std::ratio<1, 1000> >,
37          std::chrono::duration<long, std::ratio<1, 1000> > >();
38     test<std::chrono::duration<long, std::ratio<1, 100> >,
39          std::chrono::duration<int, std::ratio<1, 1000> >,
40          std::chrono::duration<long, std::ratio<1, 1000> > >();
41     test<std::chrono::duration<char, std::ratio<1, 30> >,
42          std::chrono::duration<short, std::ratio<1, 1000> >,
43          std::chrono::duration<int, std::ratio<1, 3000> > >();
44     test<std::chrono::duration<double, std::ratio<21, 1> >,
45          std::chrono::duration<short, std::ratio<15, 1> >,
46          std::chrono::duration<double, std::ratio<3, 1> > >();
47 
48   return 0;
49 }
50