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/detail/lightweight_test.hpp> 11 #include <iostream> 12 call1(boost::function<int (int)> f)13void call1(boost::function<int (int) > f) { BOOST_TEST(f(1) == 5); } call0(boost::function<int (void)> f)14void call0(boost::function<int (void)> f) { BOOST_TEST(f() == 5); } 15 linear(const int & slope)16boost::function<int (int, int)> linear(const int& slope) { 17 int BOOST_LOCAL_FUNCTION( (const bind& slope) 18 (int x)(default 1) (int y)(default 2) ) { 19 return x + slope * y; 20 } BOOST_LOCAL_FUNCTION_NAME(lin) 21 22 boost::function<int (int, int)> f = lin; 23 BOOST_TEST(f(1, 2) == 5); 24 25 call1(lin); 26 call0(lin); 27 28 return lin; 29 } 30 call(void)31void call(void) { 32 boost::function<int (int, int)> f = linear(2); 33 BOOST_TEST(f(1, 2) == 5); 34 } 35 main(void)36int main(void) { 37 call(); 38 return boost::report_errors(); 39 } 40 41