]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/bind/bind_function_object_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/bind.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";
29 template <typename Arg
>
35 template <typename Arg
>
36 Arg
operator()(Arg n
) const
44 template <typename Arg
>
50 template <typename Arg
>
51 Arg
operator()(Arg n
) const
53 return (n
<= 0) ? 1 : n
* (*this)(n
-1);
59 template <typename Arg1
, typename Arg2
>
65 template <typename Arg1
, typename Arg2
>
66 Arg1
operator()(Arg1 a
, Arg2 b
) const
74 template <typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
>
80 template <typename Arg1
, typename Arg2
, typename Arg3
, typename Arg4
>
81 Arg1
operator()(Arg1 a
, Arg2 b
, Arg3 c
, Arg4 d
) const
91 double d5
= 5, d3
= 3;
94 BOOST_TEST(bind(sqr(), arg1
)(i5
) == (i5
*i5
));
95 BOOST_TEST(bind(fact(), 4)() == 24);
96 BOOST_TEST(bind(fact(), arg1
)(i5
) == 120);
97 BOOST_TEST((int)bind(power(), arg1
, arg2
)(d5
, d3
) == (int)pow(d5
, d3
));
98 BOOST_TEST((bind(sqr(), arg1
) + 5)(i5
) == ((i5
*i5
)+5));
99 BOOST_TEST(bind(add(), arg1
, arg1
, arg1
, arg1
)(i5
) == (5+5+5+5));
103 BOOST_TEST(bind(sqr(), arg1
)(ic5
) == (ic5
*ic5
));
105 // From Steven Watanabe
108 int result
= bind(ref(s
), _1
)(x
);
109 BOOST_TEST(result
== 4);
111 return boost::report_errors();