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/config.hpp>
9 #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
10 #   error "variadic macros required"
11 #else
12 
13 #include <boost/local_function.hpp>
14 #include <boost/function.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16 #include <iostream>
17 
18 //[return_assign
call1(boost::function<int (int)> f)19 void call1(boost::function<int (int) > f) { BOOST_TEST(f(1) == 5); }
call0(boost::function<int (void)> f)20 void call0(boost::function<int (void)> f) { BOOST_TEST(f() == 5); }
21 
linear(const int & slope)22 boost::function<int (int, int)> linear(const int& slope) {
23     int BOOST_LOCAL_FUNCTION(const bind& slope,
24             int x, default 1, int y, default 2) {
25         return x + slope * y;
26     } BOOST_LOCAL_FUNCTION_NAME(lin)
27 
28     boost::function<int (int, int)> f = lin; // Assign to local variable.
29     BOOST_TEST(f(1, 2) == 5);
30 
31     call1(lin); // Pass to other functions.
32     call0(lin);
33 
34     return lin; // Return.
35 }
36 
call(void)37 void call(void) {
38     boost::function<int (int, int)> f = linear(2);
39     BOOST_TEST(f(1, 2) == 5);
40 }
41 //]
42 
main(void)43 int main(void) {
44     call();
45     return boost::report_errors();
46 }
47 
48 #endif // VARIADIC_MACROS
49 
50