duration.pass.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // <chrono>
  9. // template <class Rep1, class Period1, class Rep2, class Period2>
  10. // struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>
  11. // {
  12. // typedef chrono::duration<typename common_type<Rep1, Rep2>::type, see below }> type;
  13. // };
  14. #include <chrono>
  15. #include "test_macros.h"
  16. template <class D1, class D2, class De>
  17. void
  18. test()
  19. {
  20. typedef typename std::common_type<D1, D2>::type Dc;
  21. static_assert((std::is_same<Dc, De>::value), "");
  22. }
  23. int main(int, char**)
  24. {
  25. test<std::chrono::duration<int, std::ratio<1, 100> >,
  26. std::chrono::duration<long, std::ratio<1, 1000> >,
  27. std::chrono::duration<long, std::ratio<1, 1000> > >();
  28. test<std::chrono::duration<long, std::ratio<1, 100> >,
  29. std::chrono::duration<int, std::ratio<1, 1000> >,
  30. std::chrono::duration<long, std::ratio<1, 1000> > >();
  31. test<std::chrono::duration<char, std::ratio<1, 30> >,
  32. std::chrono::duration<short, std::ratio<1, 1000> >,
  33. std::chrono::duration<int, std::ratio<1, 3000> > >();
  34. test<std::chrono::duration<double, std::ratio<21, 1> >,
  35. std::chrono::duration<short, std::ratio<15, 1> >,
  36. std::chrono::duration<double, std::ratio<3, 1> > >();
  37. return 0;
  38. }