]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/function/function_tests_phx2.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 ==============================================================================*/
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/phoenix/core.hpp>
11 #include <boost/phoenix/operator.hpp>
12 #include <boost/phoenix/function.hpp>
14 using namespace boost::phoenix
;
15 using namespace boost::phoenix::arg_names
;
20 typedef void result_type
;
21 void operator()() const
23 cout
<< "Test lazy functions...\n";
27 function
<test_impl
> test
;
31 template <typename Arg
>
37 template <typename Arg
>
38 Arg
operator()(Arg n
) const
44 function
<sqr_impl
> sqr
;
48 template <typename Arg
>
54 template <typename Arg
>
55 Arg
operator()(Arg n
) const
57 return (n
<= 0) ? 1 : n
* (*this)(n
-1);
61 function
<fact_impl
> fact
;
65 template <typename Arg1
, typename Arg2
>
71 template <typename Arg1
, typename Arg2
>
72 Arg1
operator()(Arg1 a
, Arg2 b
) const
78 function
<pow_impl
> power
;
82 template <typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
>
88 template <typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
>
89 Arg1
operator()(Arg1 a
, Arg2 b
, Arg3 c
, Arg4 d
) const
95 function
<add_impl
> add
;
101 double d5
= 5, d3
= 3;
104 BOOST_TEST(sqr(arg1
)(i5
) == (i5
*i5
));
105 BOOST_TEST(fact(4)() == 24);
106 BOOST_TEST(fact(arg1
)(i5
) == 120);
107 BOOST_TEST((int)power(arg1
, arg2
)(d5
, d3
) == (int)pow(d5
, d3
));
108 BOOST_TEST((sqr(arg1
) + 5)(i5
) == ((i5
*i5
)+5));
109 BOOST_TEST(add(arg1
, arg1
, arg1
, arg1
)(i5
) == (5+5+5+5));
113 BOOST_TEST(sqr(arg1
)(ic5
) == (ic5
*ic5
));
115 return boost::report_errors();