]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/local_function/example/phoenix_factorial.cpp
2 // Copyright (C) 2009-2012 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0
4 // (see accompanying file LICENSE_1_0.txt or a copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 // Home at http://www.boost.org/libs/local_function
8 #include <boost/phoenix/core.hpp>
9 #include <boost/phoenix/function.hpp>
10 #include <boost/detail/lightweight_test.hpp>
13 struct factorial_impl
{ // Phoenix function from global functor.
14 template<typename Sig
>
17 template<typename This
, typename Arg
>
18 struct result
<This (Arg
)> : result
<This (Arg
const&)> {};
20 template<typename This
, typename Arg
>
21 struct result
<This (Arg
&)> { typedef Arg type
; };
23 template<typename Arg
> // Polymorphic.
24 Arg
operator()(Arg n
) const {
25 return (n
<= 0) ? 1 : n
* (*this)(n
- 1);
30 using boost::phoenix::arg_names::arg1
;
32 boost::phoenix::function
<factorial_impl
> factorial
;
35 BOOST_TEST(factorial(i
)() == 24); // Call.
36 BOOST_TEST(factorial(arg1
)(i
) == 24); // Lazy call.
37 return boost::report_errors();