brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 8eb54a0 Raw
54 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410// <chrono>11 12// round13 14// template <class ToDuration, class Rep, class Period>15//   constexpr16//   ToDuration17//   ceil(const duration<Rep, Period>& d);18 19#include <chrono>20#include <type_traits>21#include <cassert>22 23#include "test_macros.h"24 25template <class ToDuration, class FromDuration>26void27test(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 36int main(int, char**)37{38//  7290000ms is 2 hours, 1 minute, and 30 seconds39    test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2));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(-122));43 44    {45//  9000000ms is 2 hours and 30 minutes46    constexpr std::chrono::hours h1 = std::chrono::round<std::chrono::hours>(std::chrono::milliseconds(9000000));47    static_assert(h1.count() == 2, "");48    constexpr std::chrono::hours h2 = std::chrono::round<std::chrono::hours>(std::chrono::milliseconds(-9000000));49    static_assert(h2.count() == -2, "");50    }51 52  return 0;53}54