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