1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
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
13
14 #include <boost/chrono/duration.hpp>
15 #include <boost/type_traits.hpp>
16 #include <boost/detail/lightweight_test.hpp>
17 #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
18 #define NOTHING ""
19 #endif
20
21 #ifdef BOOST_NO_CXX11_CONSTEXPR
22 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C)
23 #else
24 #include <boost/static_assert.hpp>
25 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C)
26 #endif
27
28
29 template <class ToDuration, class FromDuration>
30 void
test(const FromDuration & f,const ToDuration & d)31 test(const FromDuration& f, const ToDuration& d)
32 {
33 //~ #if defined(BOOST_NO_CXX11_DECLTYPE)
34 //~ typedef BOOST_TYPEOF_TPL(boost::chrono::duration_cast<ToDuration>(f)) R;
35 //~ #else
36 //~ typedef decltype(boost::chrono::duration_cast<ToDuration>(f)) R;
37 //~ #endif
38 //~ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<R, ToDuration>::value), NOTHING, (R, ToDuration));
39 BOOST_TEST(boost::chrono::duration_cast<ToDuration>(f) == d);
40 }
41
main()42 int main()
43 {
44 test(boost::chrono::milliseconds(7265000), boost::chrono::hours(2));
45 test(boost::chrono::milliseconds(7265000), boost::chrono::minutes(121));
46 test(boost::chrono::milliseconds(7265000), boost::chrono::seconds(7265));
47 test(boost::chrono::milliseconds(7265000), boost::chrono::milliseconds(7265000));
48 test(boost::chrono::milliseconds(7265000), boost::chrono::microseconds(7265000000LL));
49 test(boost::chrono::milliseconds(7265000), boost::chrono::nanoseconds(7265000000000LL));
50 test(boost::chrono::milliseconds(7265000),
51 boost::chrono::duration<double, boost::ratio<3600> >(7265./3600));
52 test(boost::chrono::duration<int, boost::ratio<2, 3> >(9),
53 boost::chrono::duration<int, boost::ratio<3, 5> >(10));
54 {
55 BOOST_CONSTEXPR boost::chrono::hours h = boost::chrono::duration_cast<boost::chrono::hours>(boost::chrono::milliseconds(7265000));
56 BOOST_CONSTEXPR_ASSERT(h.count() == 2);
57 }
58 return boost::report_errors();
59 }
60