]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/test/time_point/time_point_cast_pass.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / chrono / test / time_point / time_point_cast_pass.cpp
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/chrono.hpp>
15 #include <boost/type_traits.hpp>
16 #include <boost/detail/lightweight_test.hpp>
17
18 #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
19 #define NOTHING ""
20 #endif
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 template <class FromDuration, class ToDuration>
29 void
30 test(const FromDuration& df, const ToDuration& d)
31 {
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;
35 FromTimePoint f(df);
36 ToTimePoint t(d);
37 //~ #if defined(BOOST_NO_CXX11_DECLTYPE)
38 //~ typedef BOOST_TYPEOF_TPL(boost::chrono::time_point_cast<ToDuration>(f)) R;
39 //~ #else
40 //~ typedef decltype(boost::chrono::time_point_cast<ToDuration>(f)) R;
41 //~ #endif
42 //~ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<R, ToTimePoint>::value), NOTHING, ());
43 BOOST_TEST(boost::chrono::time_point_cast<ToDuration>(f) == t);
44 }
45
46 int main()
47 {
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));
58 {
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);
65 }
66 return boost::report_errors();
67 }