• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 // <chrono>
12 
13 // round
14 
15 // template <class ToDuration, class Rep, class Period>
16 //   constexpr
17 //   ToDuration
18 //   ceil(const duration<Rep, Period>& d);
19 
20 #include <chrono>
21 #include <type_traits>
22 #include <cassert>
23 
24 template <class ToDuration, class FromDuration>
25 void
test(const FromDuration & f,const ToDuration & d)26 test(const FromDuration& f, const ToDuration& d)
27 {
28     {
29     typedef decltype(std::chrono::round<ToDuration>(f)) R;
30     static_assert((std::is_same<R, ToDuration>::value), "");
31     assert(std::chrono::round<ToDuration>(f) == d);
32     }
33 }
34 
main()35 int main()
36 {
37 //  7290000ms is 2 hours, 1 minute, and 30 seconds
38     test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2));
39     test(std::chrono::milliseconds(-7290000), std::chrono::hours(-2));
40     test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 122));
41     test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122));
42 
43     {
44 //  9000000ms is 2 hours and 30 minutes
45     constexpr std::chrono::hours h1 = std::chrono::round<std::chrono::hours>(std::chrono::milliseconds(9000000));
46     static_assert(h1.count() == 2, "");
47     constexpr std::chrono::hours h2 = std::chrono::round<std::chrono::hours>(std::chrono::milliseconds(-9000000));
48     static_assert(h2.count() == -2, "");
49     }
50 }
51