| 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 | |
| 11 | // <chrono> |
| 12 | |
| 13 | // ceil |
| 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 | #include "test_macros.h" |
| 25 | |
| 26 | template <class ToDuration, class FromDuration> |
| 27 | void |
| 28 | test(const FromDuration& f, const ToDuration& d) |
| 29 | { |
| 30 | { |
| 31 | typedef decltype(std::chrono::ceil<ToDuration>(f)) R; |
| 32 | static_assert((std::is_same<R, ToDuration>::value), "" ); |
| 33 | assert(std::chrono::ceil<ToDuration>(f) == d); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | int main(int, char**) |
| 38 | { |
| 39 | // 7290000ms is 2 hours, 1 minute, and 30 seconds |
| 40 | test(f: std::chrono::milliseconds( 7290000), d: std::chrono::hours( 3)); |
| 41 | test(f: std::chrono::milliseconds(-7290000), d: std::chrono::hours(-2)); |
| 42 | test(f: std::chrono::milliseconds( 7290000), d: std::chrono::minutes( 122)); |
| 43 | test(f: std::chrono::milliseconds(-7290000), d: std::chrono::minutes(-121)); |
| 44 | |
| 45 | { |
| 46 | // 9000000ms is 2 hours and 30 minutes |
| 47 | constexpr std::chrono::hours h1 = std::chrono::ceil<std::chrono::hours>(d: std::chrono::milliseconds(9000000)); |
| 48 | static_assert(h1.count() == 3, "" ); |
| 49 | constexpr std::chrono::hours h2 = std::chrono::ceil<std::chrono::hours>(d: std::chrono::milliseconds(-9000000)); |
| 50 | static_assert(h2.count() == -2, "" ); |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |