1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // Adaptation to Boost of the libcxx
10 // Copyright 2010 Vicente J. Botet Escriba
11 // Distributed under the Boost Software License, Version 1.0.
12 // See http://www.boost.org/LICENSE_1_0.txt
14 #include <boost/chrono/chrono.hpp>
15 #include <boost/type_traits.hpp>
16 #include <boost/detail/lightweight_test.hpp>
18 #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
21 #ifdef BOOST_NO_CXX11_CONSTEXPR
22 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C)
24 #include <boost/static_assert.hpp>
25 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C)
28 template <class FromDuration
, class ToDuration
>
30 test(const FromDuration
& df
, const ToDuration
& d
)
32 typedef boost::chrono::system_clock Clock
;
33 typedef boost::chrono::time_point
<Clock
, FromDuration
> FromTimePoint
;
34 typedef boost::chrono::time_point
<Clock
, ToDuration
> ToTimePoint
;
37 //~ #if defined(BOOST_NO_CXX11_DECLTYPE)
38 //~ typedef BOOST_TYPEOF_TPL(boost::chrono::time_point_cast<ToDuration>(f)) R;
40 //~ typedef decltype(boost::chrono::time_point_cast<ToDuration>(f)) R;
42 //~ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<R, ToTimePoint>::value), NOTHING, ());
43 BOOST_TEST(boost::chrono::time_point_cast
<ToDuration
>(f
) == t
);
48 test(boost::chrono::milliseconds(7265000), boost::chrono::hours(2));
49 test(boost::chrono::milliseconds(7265000), boost::chrono::minutes(121));
50 test(boost::chrono::milliseconds(7265000), boost::chrono::seconds(7265));
51 test(boost::chrono::milliseconds(7265000), boost::chrono::milliseconds(7265000));
52 test(boost::chrono::milliseconds(7265000), boost::chrono::microseconds(7265000000LL));
53 test(boost::chrono::milliseconds(7265000), boost::chrono::nanoseconds(7265000000000LL));
54 test(boost::chrono::milliseconds(7265000),
55 boost::chrono::duration
<double, boost::ratio
<3600> >(7265./3600));
56 test(boost::chrono::duration
<int, boost::ratio
<2, 3> >(9),
57 boost::chrono::duration
<int, boost::ratio
<3, 5> >(10));
59 typedef boost::chrono::system_clock Clock
;
60 typedef boost::chrono::time_point
<Clock
, boost::chrono::milliseconds
> FromTimePoint
;
61 typedef boost::chrono::time_point
<Clock
, boost::chrono::hours
> ToTimePoint
;
62 BOOST_CONSTEXPR FromTimePoint
f(boost::chrono::milliseconds(7265000));
63 BOOST_CONSTEXPR ToTimePoint tph
= boost::chrono::time_point_cast
<boost::chrono::hours
>(f
);
64 BOOST_CONSTEXPR_ASSERT(tph
.time_since_epoch().count() == 2);
66 return boost::report_errors();