]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/function/function_tests.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2007 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
10 #include <boost/detail/lightweight_test.hpp>
11 #include <boost/phoenix/core.hpp>
12 #include <boost/phoenix/operator.hpp>
13 #include <boost/phoenix/function.hpp>
15 #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
16 #include <boost/mpl/multiplies.hpp>
17 #undef BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
21 typedef void result_type
;
22 void operator()() const
24 std::cout
<< "Test lazy functions...\n";
28 boost::phoenix::function
<test_impl
> test
;
32 template <typename Signature
>
35 template <typename This
, typename Arg
>
36 struct result
<This(Arg
)>
38 typedef typename
boost::remove_reference
<Arg
>::type type
;
41 template <typename Arg
>
43 operator()(Arg n
) const
49 boost::phoenix::function
<sqr_impl
> sqr
;
53 template <typename Signature
>
56 template <typename This
, typename Arg
>
57 struct result
<This(Arg
)>
59 typedef typename
boost::remove_reference
<Arg
>::type type
;
62 template <typename Arg
>
64 operator()(Arg n
) const
66 return (n
<= 0) ? 1 : n
* (*this)(n
-1);
70 boost::phoenix::function
<fact_impl
> fact
;
75 template <typename Sig
>
78 template <typename This
, typename Arg1
, typename Arg2
>
79 struct result
<This(Arg1
, Arg2
)>
81 typedef typename
boost::remove_reference
<Arg1
>::type type
;
84 template <typename Arg1
, typename Arg2
>
86 operator()(Arg1 a
, Arg2 b
) const
88 return std::pow(a
, b
);
92 boost::phoenix::function
<pow_impl
> power
;
96 template <typename Sig
>
99 template <typename This
, typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
>
100 struct result
<This(Arg1
, Arg2
, Arg3
, Arg4
)>
102 typedef typename
boost::remove_reference
<Arg1
>::type type
;
105 template <typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
>
107 operator()(Arg1 a
, Arg2 b
, Arg3 c
, Arg4 d
) const
109 return a
+ b
+ c
+ d
;
113 boost::phoenix::function
<add_impl
> add
;
118 using boost::phoenix::arg_names::arg1
;
119 using boost::phoenix::arg_names::arg2
;
122 double d5
= 5, d3
= 3;
125 BOOST_TEST(sqr(arg1
)(i5
) == (i5
*i5
));
126 BOOST_TEST(fact(4)() == 24);
127 BOOST_TEST(fact(arg1
)(i5
) == 120);
128 BOOST_TEST((int)power(arg1
, arg2
)(d5
, d3
) == (int)std::pow(d5
, d3
));
129 BOOST_TEST((sqr(arg1
) + 5)(i5
) == ((i5
*i5
)+5));
130 BOOST_TEST(add(arg1
, arg1
, arg1
, arg1
)(i5
) == (5+5+5+5));
132 // testing composition
133 BOOST_TEST(add(arg1
, arg1
, arg1
, power(arg1
, 2))(d5
) == (5+5+5+25));
137 BOOST_TEST(sqr(arg1
)(ic5
) == (ic5
*ic5
));
139 return boost::report_errors();