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 // test mpl::plus
15
16 #define BOOST_RATIO_EXTENSIONS
17
18 #include <boost/ratio/mpl/plus.hpp>
19 #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
20 #define NOTHING ""
21 #endif
22
test()23 void test()
24 {
25 {
26 typedef boost::ratio<1, 1> R1;
27 typedef boost::mpl::int_<1> R2;
28 typedef boost::mpl::plus<R1, R2> R;
29 BOOST_RATIO_STATIC_ASSERT(R::num == 2 && R::den == 1, NOTHING, ());
30 typedef boost::mpl::plus<R, R2> RR;
31 BOOST_RATIO_STATIC_ASSERT(RR::num == 3 && RR::den == 1, NOTHING, ());
32 }
33 {
34 typedef boost::mpl::int_<1> R1;
35 typedef boost::ratio<1, 2> R2;
36 typedef boost::mpl::plus<R1, R2> R;
37 BOOST_RATIO_STATIC_ASSERT(R::num == 3 && R::den == 2, NOTHING, ());
38 }
39 {
40 typedef boost::ratio<-1, 2> R1;
41 typedef boost::ratio<1, 1> R2;
42 typedef boost::mpl::int_<0> R3;
43 typedef boost::mpl::plus<R1, R2, R3> R;
44 BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
45 }
46 {
47 typedef boost::ratio<1, -2> R1;
48 typedef boost::ratio<1, 1> R2;
49 typedef boost::mpl::int_<0> R3;
50 typedef boost::mpl::plus<R1, R2, R3> R;
51 BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ());
52 }
53 {
54 typedef boost::ratio<1, 2> R1;
55 typedef boost::ratio<-1, 1> R2;
56 typedef boost::mpl::int_<0> R3;
57 typedef boost::mpl::plus<R1, R2, R3> R;
58 BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ());
59 }
60 {
61 typedef boost::ratio<1, 2> R1;
62 typedef boost::ratio<1, -1> R2;
63 typedef boost::mpl::int_<0> R3;
64 typedef boost::mpl::plus<R1, R2, R3> R;
65 BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ());
66 }
67 {
68 typedef boost::ratio<56987354, 467584654> R1;
69 typedef boost::ratio<544668, 22145> R2;
70 typedef boost::mpl::int_<0> R3;
71 typedef boost::mpl::plus<R1, R2, R3> R;
72 BOOST_RATIO_STATIC_ASSERT(R::num == 127970191639601LL && R::den == 5177331081415LL, NOTHING, ());
73 }
74 {
75 typedef boost::ratio<BOOST_RATIO_INTMAX_T_MAX, 1> R1;
76 typedef boost::ratio<-1, 1> R2;
77 typedef boost::mpl::int_<0> R3;
78 typedef boost::mpl::plus<R1, R2, R3>::type RT;
79 }
80
81 }
82
func(boost::ratio<5,6> s)83 boost::intmax_t func(boost::ratio<5,6> s) {
84 return s.num;
85 }
86
87
test_conversion()88 boost::intmax_t test_conversion() {
89 return func(
90 boost::mpl::plus<
91 boost::ratio<1,2>,
92 boost::ratio<1,3>
93 >
94 ()
95 );
96 }
97
98