diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
commit | b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d (patch) | |
tree | 13f237c02db4d1894ab06884d1b739344766bede /test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp | |
parent | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff) | |
download | src-b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d.tar.gz src-b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d.zip |
Vendor import of libc++ trunk r256633:vendor/libc++/r256633
Notes
Notes:
svn path=/vendor/libc++/dist/; revision=292928
svn path=/vendor/libc++/r256633/; revision=292930; tag=vendor/libc++/r256633
Diffstat (limited to 'test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp')
-rw-r--r-- | test/std/utilities/time/time.duration/time.duration.cast/round.pass.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
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 000000000000..e50b85c991a2 --- /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 +// <chrono> + +// round + +// template <class ToDuration, class Rep, class Period> +// constexpr +// ToDuration +// ceil(const duration<Rep, Period>& d); + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class ToDuration, class FromDuration> +void +test(const FromDuration& f, const ToDuration& d) +{ + { + typedef decltype(std::chrono::round<ToDuration>(f)) R; + static_assert((std::is_same<R, ToDuration>::value), ""); + assert(std::chrono::round<ToDuration>(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::hours>(std::chrono::milliseconds(9000000)); + static_assert(h1.count() == 2, ""); + constexpr std::chrono::hours h2 = std::chrono::round<std::chrono::hours>(std::chrono::milliseconds(-9000000)); + static_assert(h2.count() == -2, ""); + } +} |