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