1 /*=============================================================================
2     Copyright (c) 2001-2003 Joel de Guzman
3 
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 ==============================================================================*/
7 #include <vector>
8 #include <algorithm>
9 #include <iostream>
10 #include <boost/phoenix/core.hpp>
11 #include <boost/phoenix/function.hpp>
12 
13 struct factorial_impl
14 {
15     template <typename Sig>
16     struct result;
17 
18     template <typename This, typename Arg>
19     struct result<This(Arg)>
20         : result<This(Arg const &)>
21     {};
22 
23     template <typename This, typename Arg>
24     struct result<This(Arg &)>
25     {
26         typedef Arg type;
27     };
28 
29     template <typename Arg>
operator ()factorial_impl30     Arg operator()(Arg n) const
31     {
32         return (n <= 0) ? 1 : n * this->operator()(n-1);
33     }
34 };
35 
36 
37 int
main()38 main()
39 {
40     using boost::phoenix::arg_names::arg1;
41     boost::phoenix::function<factorial_impl> factorial;
42     int i = 4;
43     std::cout << factorial(i)() << std::endl;
44     std::cout << factorial(arg1)(i) << std::endl;
45     return 0;
46 }
47