From 223df2ef0f543f7fef9270b3b34b9c73c869a006 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 5 Nov 2015 19:33:59 +0000 Subject: [PATCH] Implement P0092R1 for C++1z git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@252195 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/chrono | 123 ++++++++++++++++++ .../time.duration.alg/abs.fail.cpp | 27 ++++ .../time.duration.alg/abs.pass.cpp | 50 +++++++ .../time.duration.cast/ceil.fail.cpp | 26 ++++ .../time.duration.cast/ceil.pass.cpp | 51 ++++++++ .../time.duration.cast/floor.fail.cpp | 26 ++++ .../time.duration.cast/floor.pass.cpp | 50 +++++++ .../time.duration.cast/round.fail.cpp | 26 ++++ .../time.duration.cast/round.pass.cpp | 50 +++++++ .../time.point/time.point.cast/ceil.fail.cpp | 26 ++++ .../time.point/time.point.cast/ceil.pass.cpp | 69 ++++++++++ .../time.point/time.point.cast/floor.fail.cpp | 26 ++++ .../time.point/time.point.cast/floor.pass.cpp | 68 ++++++++++ .../time.point/time.point.cast/round.fail.cpp | 26 ++++ .../time.point/time.point.cast/round.pass.cpp | 68 ++++++++++ www/cxx1z_status.html | 2 +- 16 files changed, 713 insertions(+), 1 deletion(-) create mode 100644 test/std/utilities/time/time.duration/time.duration.alg/abs.fail.cpp create mode 100644 test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp create mode 100644 test/std/utilities/time/time.duration/time.duration.cast/ceil.fail.cpp create mode 100644 test/std/utilities/time/time.duration/time.duration.cast/ceil.pass.cpp create mode 100644 test/std/utilities/time/time.duration/time.duration.cast/floor.fail.cpp create mode 100644 test/std/utilities/time/time.duration/time.duration.cast/floor.pass.cpp create mode 100644 test/std/utilities/time/time.duration/time.duration.cast/round.fail.cpp create mode 100644 test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp create mode 100644 test/std/utilities/time/time.point/time.point.cast/ceil.fail.cpp create mode 100644 test/std/utilities/time/time.point/time.point.cast/ceil.pass.cpp create mode 100644 test/std/utilities/time/time.point/time.point.cast/floor.fail.cpp create mode 100644 test/std/utilities/time/time.point/time.point.cast/floor.pass.cpp create mode 100644 test/std/utilities/time/time.point/time.point.cast/round.fail.cpp create mode 100644 test/std/utilities/time/time.point/time.point.cast/round.pass.cpp diff --git a/include/chrono b/include/chrono index 9229234c..aac05870 100644 --- a/include/chrono +++ b/include/chrono @@ -194,6 +194,13 @@ template template ToDuration duration_cast(const duration& d); +template + constexpr ToDuration floor(const duration& d); // C++17 +template + constexpr ToDuration ceil(const duration& d); // C++17 +template + constexpr ToDuration round(const duration& d); // C++17 + // time_point arithmetic (all constexpr in C++14) template time_point>::type> @@ -227,6 +234,20 @@ template template time_point time_point_cast(const time_point& t); +template + constexpr time_point + floor(const time_point& tp); // C++17 + +template + constexpr time_point + ceil(const time_point& tp); // C++17 + +template + constexpr time_point + round(const time_point& tp); // C++17 + +template + constexpr duration abs(duration d); // C++17 // Clocks class system_clock @@ -401,6 +422,58 @@ public: _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();} }; +#if _LIBCPP_STD_VER > 14 +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +floor(const duration<_Rep, _Period>& __d) +{ + _ToDuration __t = duration_cast<_ToDuration>(__d); + if (__t > __d) + __t = __t - _ToDuration{1}; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +ceil(const duration<_Rep, _Period>& __d) +{ + _ToDuration __t = duration_cast<_ToDuration>(__d); + if (__t < __d) + __t = __t + _ToDuration{1}; + return __t; +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +round(const duration<_Rep, _Period>& __d) +{ + _ToDuration __lower = floor<_ToDuration>(__d); + _ToDuration __upper = __lower + _ToDuration{1}; + auto __lowerDiff = __d - __lower; + auto __upperDiff = __upper - __d; + if (__lowerDiff < __upperDiff) + return __lower; + if (__lowerDiff > __upperDiff) + return __upper; + return __lower.count() & 1 ? __upper : __lower; +} +#endif + // duration template @@ -807,6 +880,56 @@ time_point_cast(const time_point<_Clock, _Duration>& __t) return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); } +#if _LIBCPP_STD_VER > 14 +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration> +>::type +floor(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration> +>::type +ceil(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration> +>::type +round(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + numeric_limits<_Rep>::is_signed, + duration<_Rep, _Period> +>::type +abs(duration<_Rep, _Period> __d) +{ + return __d >= __d.zero() ? __d : -__d; +} +#endif + // time_point == template diff --git a/test/std/utilities/time/time.duration/time.duration.alg/abs.fail.cpp b/test/std/utilities/time/time.duration/time.duration.alg/abs.fail.cpp new file mode 100644 index 00000000..221004c5 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.alg/abs.fail.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// ceil + +// template +// constexpr duration abs(duration d) + +// This function shall not participate in overload resolution unless numeric_limits::is_signed is true. + +#include + +typedef std::chrono::duration unsigned_secs; + +int main() +{ + std::chrono::abs(unsigned_secs(0)); +} diff --git a/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp b/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp new file mode 100644 index 00000000..ec32c37a --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 + +// + +// abs + +// template +// constexpr duration abs(duration d) + +#include +#include +#include + +template +void +test(const Duration& f, const Duration& d) +{ + { + typedef decltype(std::chrono::abs(f)) R; + static_assert((std::is_same::value), ""); + assert(std::chrono::abs(f) == d); + } +} + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::milliseconds( 7290000)); + test(std::chrono::milliseconds(-7290000), std::chrono::milliseconds( 7290000)); + test(std::chrono::minutes( 122), std::chrono::minutes( 122)); + test(std::chrono::minutes(-122), std::chrono::minutes( 122)); + test(std::chrono::hours(0), std::chrono::hours(0)); + + { +// 9000000ms is 2 hours and 30 minutes + constexpr std::chrono::hours h1 = std::chrono::abs(std::chrono::hours(-3)); + static_assert(h1.count() == 3, ""); + constexpr std::chrono::hours h2 = std::chrono::abs(std::chrono::hours(3)); + static_assert(h2.count() == 3, ""); + } +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/ceil.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cast/ceil.fail.cpp new file mode 100644 index 00000000..909e8573 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/ceil.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// ceil + +// template +// ToDuration +// ceil(const duration& d); + +// ToDuration shall be an instantiation of duration. + +#include + +int main() +{ + std::chrono::ceil(std::chrono::milliseconds(3)); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/ceil.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cast/ceil.pass.cpp new file mode 100644 index 00000000..6fb73b97 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/ceil.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 + +// + +// ceil + +// template +// constexpr +// ToDuration +// ceil(const duration& d); + +#include +#include +#include + +template +void +test(const FromDuration& f, const ToDuration& d) +{ + { + typedef decltype(std::chrono::ceil(f)) R; + static_assert((std::is_same::value), ""); + assert(std::chrono::ceil(f) == d); + } +} + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::hours( 3)); + 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(-121)); + + { +// 9000000ms is 2 hours and 30 minutes + constexpr std::chrono::hours h1 = std::chrono::ceil(std::chrono::milliseconds(9000000)); + static_assert(h1.count() == 3, ""); + constexpr std::chrono::hours h2 = std::chrono::ceil(std::chrono::milliseconds(-9000000)); + static_assert(h2.count() == -2, ""); + } +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/floor.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cast/floor.fail.cpp new file mode 100644 index 00000000..14d9ca87 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/floor.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// floor + +// template +// ToDuration +// floor(const duration& d); + +// ToDuration shall be an instantiation of duration. + +#include + +int main() +{ + std::chrono::floor(std::chrono::milliseconds(3)); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/floor.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cast/floor.pass.cpp new file mode 100644 index 00000000..57929dd9 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/floor.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// floor + +// template +// constexpr +// ToDuration +// floor(const duration& d); + +#include +#include +#include + +template +void +test(const FromDuration& f, const ToDuration& d) +{ + { + typedef decltype(std::chrono::floor(f)) R; + static_assert((std::is_same::value), ""); + assert(std::chrono::floor(f) == d); + } +} + +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(-3)); + test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 121)); + test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122)); + + { +// 9000000ms is 2 hours and 30 minutes + constexpr std::chrono::hours h1 = std::chrono::floor(std::chrono::milliseconds(9000000)); + static_assert(h1.count() == 2, ""); + constexpr std::chrono::hours h2 = std::chrono::floor(std::chrono::milliseconds(-9000000)); + static_assert(h2.count() == -3, ""); + } +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/round.fail.cpp b/test/std/utilities/time/time.duration/time.duration.cast/round.fail.cpp new file mode 100644 index 00000000..6f9f5bd2 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/round.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// round + +// template +// ToDuration +// round(const duration& d); + +// ToDuration shall be an instantiation of duration. + +#include + +int main() +{ + std::chrono::round(std::chrono::milliseconds(3)); +} diff --git a/test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp b/test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp new file mode 100644 index 00000000..e50b85c9 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// round + +// template +// constexpr +// ToDuration +// ceil(const duration& d); + +#include +#include +#include + +template +void +test(const FromDuration& f, const ToDuration& d) +{ + { + typedef decltype(std::chrono::round(f)) R; + static_assert((std::is_same::value), ""); + assert(std::chrono::round(f) == d); + } +} + +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 + constexpr std::chrono::hours h1 = std::chrono::round(std::chrono::milliseconds(9000000)); + static_assert(h1.count() == 2, ""); + constexpr std::chrono::hours h2 = std::chrono::round(std::chrono::milliseconds(-9000000)); + static_assert(h2.count() == -2, ""); + } +} diff --git a/test/std/utilities/time/time.point/time.point.cast/ceil.fail.cpp b/test/std/utilities/time/time.point/time.point.cast/ceil.fail.cpp new file mode 100644 index 00000000..1c92d75b --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/ceil.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// ceil + +// template +// time_point +// ceil(const time_point& t); + +// ToDuration shall be an instantiation of duration. + +#include + +int main() +{ + std::chrono::ceil(std::chrono::system_clock::now()); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/ceil.pass.cpp b/test/std/utilities/time/time.point/time.point.cast/ceil.pass.cpp new file mode 100644 index 00000000..379929c7 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/ceil.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// ceil + +// template +// time_point +// ceil(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::ceil(f)) R; + static_assert((std::is_same::value), ""); + assert(std::chrono::ceil(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::ceil(f) == t, ""); + } +} + + +int main() +{ +// 7290000ms is 2 hours, 1 minute, and 30 seconds + test(std::chrono::milliseconds( 7290000), std::chrono::hours( 3)); + 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(-121)); + +// 9000000ms is 2 hours and 30 minutes + test_constexpr (); + test_constexpr (); + test_constexpr (); + test_constexpr (); + + test_constexpr (); + test_constexpr (); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/floor.fail.cpp b/test/std/utilities/time/time.point/time.point.cast/floor.fail.cpp new file mode 100644 index 00000000..ea48e121 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/floor.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// floor + +// template +// time_point +// floor(const time_point& t); + +// ToDuration shall be an instantiation of duration. + +#include + +int main() +{ + std::chrono::floor(std::chrono::system_clock::now()); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/floor.pass.cpp b/test/std/utilities/time/time.point/time.point.cast/floor.pass.cpp new file mode 100644 index 00000000..d0a908fa --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/floor.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// floor + +// template +// time_point +// floor(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::floor(f)) R; + static_assert((std::is_same::value), ""); + assert(std::chrono::floor(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::floor(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(-3)); + test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 121)); + 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 (); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/round.fail.cpp b/test/std/utilities/time/time.point/time.point.cast/round.fail.cpp new file mode 100644 index 00000000..53c14f47 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/round.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// + +// round + +// template +// time_point +// round(const time_point& t); + +// ToDuration shall be an instantiation of duration. + +#include + +int main() +{ + std::chrono::round(std::chrono::system_clock::now()); +} diff --git a/test/std/utilities/time/time.point/time.point.cast/round.pass.cpp b/test/std/utilities/time/time.point/time.point.cast/round.pass.cpp new file mode 100644 index 00000000..ab8bf3a7 --- /dev/null +++ b/test/std/utilities/time/time.point/time.point.cast/round.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: 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 (); +} diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 73d8a1cb..8397a90c 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -72,7 +72,7 @@ P0004R1LWGRemove Deprecated iostreams aliases.KonaComplete3.8 P0006R0LWGAdopt Type Traits Variable Templates for C++17.KonaIn progress - P0092R1LWGPolishing <chrono>Kona + P0092R1LWGPolishing <chrono>KonaComplete3.8 P0007R1LWGConstant View: A proposal for a std::as_const helper function template.KonaIn progress P0156R0LWGVariadic lock_guard(rev 3).Kona P0074R0LWGMaking std::owner_less more flexibleKona