Implement P0092R1 for C++1z
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@252195 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -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));
|
||||
}
|
@@ -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, "");
|
||||
}
|
||||
}
|
@@ -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));
|
||||
}
|
@@ -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, "");
|
||||
}
|
||||
}
|
@@ -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));
|
||||
}
|
@@ -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, "");
|
||||
}
|
||||
}
|
@@ -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));
|
||||
}
|
@@ -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, "");
|
||||
}
|
||||
}
|
@@ -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());
|
||||
}
|
@@ -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> ();
|
||||
}
|
@@ -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());
|
||||
}
|
@@ -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> ();
|
||||
}
|
@@ -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());
|
||||
}
|
@@ -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> ();
|
||||
}
|
Reference in New Issue
Block a user