• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
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
7 
8 #include <boost/local_function.hpp>
9 #include <boost/function.hpp>
10 #include <boost/phoenix/core.hpp>
11 #include <boost/phoenix/function.hpp>
12 #include <boost/detail/lightweight_test.hpp>
13 
14 //[phoenix_factorial_local
main(void)15 int main(void) {
16     using boost::phoenix::arg_names::arg1;
17 
18     int BOOST_LOCAL_FUNCTION(int n) { // Unfortunately, monomorphic.
19         return (n <= 0) ? 1 : n * factorial_impl(n - 1);
20     } BOOST_LOCAL_FUNCTION_NAME(recursive factorial_impl)
21 
22     boost::phoenix::function< boost::function<int (int)> >
23             factorial(factorial_impl); // Phoenix function from local function.
24 
25     int i = 4;
26     BOOST_TEST(factorial(i)() == 24);      // Call.
27     BOOST_TEST(factorial(arg1)(i) == 24);  // Lazy call.
28     return boost::report_errors();
29 }
30 //]
31 
32