Implement P0092R1 for C++1z
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@252195 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/chrono b/include/chrono
index 9229234..aac0587 100644
--- a/include/chrono
+++ b/include/chrono
@@ -194,6 +194,13 @@
template <class ToDuration, class Rep, class Period>
ToDuration duration_cast(const duration<Rep, Period>& d);
+template <class ToDuration, class Rep, class Period>
+ constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17
+template <class ToDuration, class Rep, class Period>
+ constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17
+template <class ToDuration, class Rep, class Period>
+ constexpr ToDuration round(const duration<Rep, Period>& d); // C++17
+
// time_point arithmetic (all constexpr in C++14)
template <class Clock, class Duration1, class Rep2, class Period2>
time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
@@ -227,6 +234,20 @@
template <class ToDuration, class Clock, class Duration>
time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
+template <class ToDuration, class Clock, class Duration>
+ constexpr time_point<Clock, ToDuration>
+ floor(const time_point<Clock, Duration>& tp); // C++17
+
+template <class ToDuration, class Clock, class Duration>
+ constexpr time_point<Clock, ToDuration>
+ ceil(const time_point<Clock, Duration>& tp); // C++17
+
+template <class ToDuration, class Clock, class Duration>
+ constexpr time_point<Clock, ToDuration>
+ round(const time_point<Clock, Duration>& tp); // C++17
+
+template <class Rep, class Period>
+ constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17
// Clocks
class system_clock
@@ -401,6 +422,58 @@
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();}
};
+#if _LIBCPP_STD_VER > 14
+template <class _ToDuration, class _Rep, class _Period>
+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 <class _ToDuration, class _Rep, class _Period>
+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 <class _ToDuration, class _Rep, class _Period>
+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 <class _Rep, class _Period>
@@ -807,6 +880,56 @@
return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
}
+#if _LIBCPP_STD_VER > 14
+template <class _ToDuration, class _Clock, class _Duration>
+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 <class _ToDuration, class _Clock, class _Duration>
+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 <class _ToDuration, class _Clock, class _Duration>
+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 <class _Rep, class _Period>
+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 <class _Clock, class _Duration1, class _Duration2>
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 0000000..221004c
--- /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
+// <chrono>
+
+// ceil
+
+// template <class Rep, class Period>
+// constexpr duration<Rep, Period> abs(duration<Rep, Period> d)
+
+// This function shall not participate in overload resolution unless numeric_limits<Rep>::is_signed is true.
+
+#include <chrono>
+
+typedef std::chrono::duration<unsigned> 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 0000000..ec32c37
--- /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
+
+// <chrono>
+
+// abs
+
+// template <class Rep, class Period>
+// constexpr duration<Rep, Period> abs(duration<Rep, Period> d)
+
+#include <chrono>
+#include <type_traits>
+#include <cassert>
+
+template <class Duration>
+void
+test(const Duration& f, const Duration& d)
+{
+ {
+ typedef decltype(std::chrono::abs(f)) R;
+ static_assert((std::is_same<R, Duration>::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 0000000..909e857
--- /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
+// <chrono>
+
+// ceil
+
+// template <class ToDuration, class Rep, class Period>
+// ToDuration
+// ceil(const duration<Rep, Period>& d);
+
+// ToDuration shall be an instantiation of duration.
+
+#include <chrono>
+
+int main()
+{
+ std::chrono::ceil<int>(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 0000000..6fb73b9
--- /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
+
+// <chrono>
+
+// ceil
+
+// 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::ceil<ToDuration>(f)) R;
+ static_assert((std::is_same<R, ToDuration>::value), "");
+ assert(std::chrono::ceil<ToDuration>(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::hours>(std::chrono::milliseconds(9000000));
+ static_assert(h1.count() == 3, "");
+ constexpr std::chrono::hours h2 = std::chrono::ceil<std::chrono::hours>(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 0000000..14d9ca8
--- /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
+// <chrono>
+
+// floor
+
+// template <class ToDuration, class Rep, class Period>
+// ToDuration
+// floor(const duration<Rep, Period>& d);
+
+// ToDuration shall be an instantiation of duration.
+
+#include <chrono>
+
+int main()
+{
+ std::chrono::floor<int>(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 0000000..57929dd
--- /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
+// <chrono>
+
+// floor
+
+// template <class ToDuration, class Rep, class Period>
+// constexpr
+// ToDuration
+// floor(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::floor<ToDuration>(f)) R;
+ static_assert((std::is_same<R, ToDuration>::value), "");
+ assert(std::chrono::floor<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(-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::hours>(std::chrono::milliseconds(9000000));
+ static_assert(h1.count() == 2, "");
+ constexpr std::chrono::hours h2 = std::chrono::floor<std::chrono::hours>(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 0000000..6f9f5bd
--- /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
+// <chrono>
+
+// round
+
+// template <class ToDuration, class Rep, class Period>
+// ToDuration
+// round(const duration<Rep, Period>& d);
+
+// ToDuration shall be an instantiation of duration.
+
+#include <chrono>
+
+int main()
+{
+ std::chrono::round<int>(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 0000000..e50b85c
--- /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, "");
+ }
+}
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 0000000..1c92d75
--- /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
+// <chrono>
+
+// ceil
+
+// template <class ToDuration, class Clock, class Duration>
+// time_point<Clock, ToDuration>
+// ceil(const time_point<Clock, Duration>& t);
+
+// ToDuration shall be an instantiation of duration.
+
+#include <chrono>
+
+int main()
+{
+ std::chrono::ceil<int>(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 0000000..379929c
--- /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
+// <chrono>
+
+// ceil
+
+// template <class ToDuration, class Clock, class Duration>
+// time_point<Clock, ToDuration>
+// ceil(const time_point<Clock, Duration>& t);
+
+#include <chrono>
+#include <type_traits>
+#include <cassert>
+
+template <class FromDuration, class ToDuration>
+void
+test(const FromDuration& df, const ToDuration& d)
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint;
+ typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint;
+ {
+ FromTimePoint f(df);
+ ToTimePoint t(d);
+ typedef decltype(std::chrono::ceil<ToDuration>(f)) R;
+ static_assert((std::is_same<R, ToTimePoint>::value), "");
+ assert(std::chrono::ceil<ToDuration>(f) == t);
+ }
+}
+
+template<class FromDuration, long long From, class ToDuration, long long To>
+void test_constexpr ()
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint;
+ typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint;
+ {
+ constexpr FromTimePoint f{FromDuration{From}};
+ constexpr ToTimePoint t{ToDuration{To}};
+ static_assert(std::chrono::ceil<ToDuration>(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<std::chrono::milliseconds, 9000000, std::chrono::hours, 3> ();
+ test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::hours, -2> ();
+ test_constexpr<std::chrono::milliseconds, 9000001, std::chrono::minutes, 151> ();
+ test_constexpr<std::chrono::milliseconds,-9000001, std::chrono::minutes,-150> ();
+
+ test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::seconds, 9000> ();
+ test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::seconds,-9000> ();
+}
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 0000000..ea48e12
--- /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
+// <chrono>
+
+// floor
+
+// template <class ToDuration, class Clock, class Duration>
+// time_point<Clock, ToDuration>
+// floor(const time_point<Clock, Duration>& t);
+
+// ToDuration shall be an instantiation of duration.
+
+#include <chrono>
+
+int main()
+{
+ std::chrono::floor<int>(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 0000000..d0a908f
--- /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
+// <chrono>
+
+// floor
+
+// template <class ToDuration, class Clock, class Duration>
+// time_point<Clock, ToDuration>
+// floor(const time_point<Clock, Duration>& t);
+
+#include <chrono>
+#include <type_traits>
+#include <cassert>
+
+template <class FromDuration, class ToDuration>
+void
+test(const FromDuration& df, const ToDuration& d)
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint;
+ typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint;
+ {
+ FromTimePoint f(df);
+ ToTimePoint t(d);
+ typedef decltype(std::chrono::floor<ToDuration>(f)) R;
+ static_assert((std::is_same<R, ToTimePoint>::value), "");
+ assert(std::chrono::floor<ToDuration>(f) == t);
+ }
+}
+
+template<class FromDuration, long long From, class ToDuration, long long To>
+void test_constexpr ()
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint;
+ typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint;
+ {
+ constexpr FromTimePoint f{FromDuration{From}};
+ constexpr ToTimePoint t{ToDuration{To}};
+ static_assert(std::chrono::floor<ToDuration>(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<std::chrono::milliseconds, 9000000, std::chrono::hours, 2> ();
+ test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::hours, -3> ();
+ test_constexpr<std::chrono::milliseconds, 9000001, std::chrono::minutes, 150> ();
+ test_constexpr<std::chrono::milliseconds,-9000001, std::chrono::minutes,-151> ();
+
+ test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::seconds, 9000> ();
+ test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::seconds,-9000> ();
+}
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 0000000..53c14f4
--- /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
+// <chrono>
+
+// round
+
+// template <class ToDuration, class Clock, class Duration>
+// time_point<Clock, ToDuration>
+// round(const time_point<Clock, Duration>& t);
+
+// ToDuration shall be an instantiation of duration.
+
+#include <chrono>
+
+int main()
+{
+ std::chrono::round<int>(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 0000000..ab8bf3a
--- /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
+// <chrono>
+
+// round
+
+// template <class ToDuration, class Clock, class Duration>
+// time_point<Clock, ToDuration>
+// round(const time_point<Clock, Duration>& t);
+
+#include <chrono>
+#include <type_traits>
+#include <cassert>
+
+template <class FromDuration, class ToDuration>
+void
+test(const FromDuration& df, const ToDuration& d)
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint;
+ typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint;
+ {
+ FromTimePoint f(df);
+ ToTimePoint t(d);
+ typedef decltype(std::chrono::round<ToDuration>(f)) R;
+ static_assert((std::is_same<R, ToTimePoint>::value), "");
+ assert(std::chrono::round<ToDuration>(f) == t);
+ }
+}
+
+template<class FromDuration, long long From, class ToDuration, long long To>
+void test_constexpr ()
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint;
+ typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint;
+ {
+ constexpr FromTimePoint f{FromDuration{From}};
+ constexpr ToTimePoint t{ToDuration{To}};
+ static_assert(std::chrono::round<ToDuration>(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<std::chrono::milliseconds, 9000000, std::chrono::hours, 2> ();
+ test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::hours, -2> ();
+ test_constexpr<std::chrono::milliseconds, 9000001, std::chrono::minutes, 150> ();
+ test_constexpr<std::chrono::milliseconds,-9000001, std::chrono::minutes,-150> ();
+
+ test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::seconds, 9000> ();
+ test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::seconds,-9000> ();
+}
diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html
index 73d8a1c..8397a90 100644
--- a/www/cxx1z_status.html
+++ b/www/cxx1z_status.html
@@ -72,7 +72,7 @@
<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0004R1.html">P0004R1</a></td><td>LWG</td><td>Remove Deprecated iostreams aliases.</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0006R0.html">P0006R0</a></td><td>LWG</td><td>Adopt Type Traits Variable Templates for C++17.</td><td>Kona</td><td>In progress</td><td></td></tr>
- <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0092R1.html">P0092R1</a></td><td>LWG</td><td>Polishing <chrono></td><td>Kona</td><td></td><td></td></tr>
+ <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0092R1.html">P0092R1</a></td><td>LWG</td><td>Polishing <chrono></td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0007R1.html">P0007R1</a></td><td>LWG</td><td>Constant View: A proposal for a <tt>std::as_const</tt> helper function template.</td><td>Kona</td><td>In progress</td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0156R0.htm" >P0156R0</a></td><td>LWG</td><td>Variadic lock_guard(rev 3).</td><td>Kona</td><td></td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0074R0.html">P0074R0</a></td><td>LWG</td><td>Making <tt>std::owner_less</tt> more flexible</td><td>Kona</td><td></td><td></td></tr>