]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/test/duration/constructor_pass.cpp
b744e159c56ac1c7b59966472dba815f9a44f2af
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
15 #include <boost/chrono/duration.hpp>
16 #include <boost/detail/lightweight_test.hpp>
22 #ifdef BOOST_NO_CXX11_CONSTEXPR
23 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C)
25 #include <boost/static_assert.hpp>
26 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C)
35 BOOST_TEST(d
.count() == typename
D::rep());
39 BOOST_CONSTEXPR_ASSERT(d
.count() == typename
D::rep());
43 template <class D
, class R
>
49 BOOST_TEST(d
.count() == r
);
55 // exact conversions allowed for integral reps
57 boost::chrono::milliseconds
ms(1);
58 boost::chrono::microseconds us
= ms
;
59 BOOST_TEST(us
.count() == 1000);
61 BOOST_CONSTEXPR
boost::chrono::milliseconds
ms(1);
62 BOOST_CONSTEXPR
boost::chrono::microseconds us
= ms
;
63 BOOST_CONSTEXPR_ASSERT(us
.count() == 1000);
66 // inexact conversions allowed for floating point reps
68 boost::chrono::duration
<double, boost::micro
> us(1);
69 boost::chrono::duration
<double, boost::milli
> ms
= us
;
70 BOOST_TEST(ms
.count() == 1./1000);
72 BOOST_CONSTEXPR
boost::chrono::duration
<double, boost::micro
> us(1);
73 BOOST_CONSTEXPR
boost::chrono::duration
<double, boost::milli
> ms
= us
;
74 BOOST_CONSTEXPR_ASSERT(ms
.count() == 1./1000);
77 // Convert int to float
79 boost::chrono::duration
<int> i(3);
80 boost::chrono::duration
<double> d
= i
;
81 BOOST_TEST(d
.count() == 3);
83 BOOST_CONSTEXPR
boost::chrono::duration
<int> i(3);
84 BOOST_CONSTEXPR
boost::chrono::duration
<double> d
= i
;
85 BOOST_CONSTEXPR_ASSERT(d
.count() == 3);
88 // default constructor
90 check_default
<boost::chrono::duration
<Rep
> >();
92 // constructor from rep
94 check_from_rep
<boost::chrono::duration
<int> >(5);
96 BOOST_CONSTEXPR
boost::chrono::duration
<int> d(5);
97 BOOST_CONSTEXPR_ASSERT(d
.count() == 5);
99 check_from_rep
<boost::chrono::duration
<int, boost::ratio
<3, 2> > >(5);
101 BOOST_CONSTEXPR
boost::chrono::duration
<int, boost::ratio
<3, 2> > d(5);
102 BOOST_CONSTEXPR_ASSERT(d
.count() == 5);
104 check_from_rep
<boost::chrono::duration
<Rep
, boost::ratio
<3, 2> > >(Rep(3));
106 BOOST_CONSTEXPR
boost::chrono::duration
<Rep
, boost::ratio
<3, 2> > d(Rep(3));
107 BOOST_CONSTEXPR_ASSERT(d
.count() == Rep(3));
109 check_from_rep
<boost::chrono::duration
<double, boost::ratio
<2, 3> > >(5.5);
111 BOOST_CONSTEXPR
boost::chrono::duration
<double, boost::ratio
<3, 2> > d(5.5);
112 BOOST_CONSTEXPR_ASSERT(d
.count() == 5.5);
117 // constructor from other rep
119 boost::chrono::duration
<double> d(5);
120 BOOST_TEST(d
.count() == 5);
122 BOOST_CONSTEXPR
boost::chrono::duration
<double> d(5);
123 BOOST_CONSTEXPR_ASSERT(d
.count() == 5);
127 return boost::report_errors();