//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11, c++14 // // round // template // time_point // round(const time_point& t); #include #include #include template void test(const FromDuration& df, const ToDuration& d) { typedef std::chrono::system_clock Clock; typedef std::chrono::time_point FromTimePoint; typedef std::chrono::time_point ToTimePoint; { FromTimePoint f(df); ToTimePoint t(d); typedef decltype(std::chrono::round(f)) R; static_assert((std::is_same::value), ""); assert(std::chrono::round(f) == t); } } template void test_constexpr () { typedef std::chrono::system_clock Clock; typedef std::chrono::time_point FromTimePoint; typedef std::chrono::time_point ToTimePoint; { constexpr FromTimePoint f{FromDuration{From}}; constexpr ToTimePoint t{ToDuration{To}}; static_assert(std::chrono::round(f) == t, ""); } } int main() { // 7290000ms is 2 hours, 1 minute, and 30 seconds test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2)); test(std::chrono::milliseconds(-7290000), std::chrono::hours(-2)); test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 122)); test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122)); // 9000000ms is 2 hours and 30 minutes test_constexpr (); test_constexpr (); test_constexpr (); test_constexpr (); test_constexpr (); test_constexpr (); }