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/typeof/typeof.hpp>
11#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
12#include <boost/detail/lightweight_test.hpp>
13
14BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function, 1)
15
16boost::function<int (int)> derivative(boost::function<int (int)>& f, int dx) {
17 int BOOST_LOCAL_FUNCTION( (bind& f) (const bind dx) (int x) ) {
18 return (f(x + dx) - f(x)) / dx;
19 } BOOST_LOCAL_FUNCTION_NAME(deriv)
20
21 return deriv;
22}
23
24int main(void) {
25 int BOOST_LOCAL_FUNCTION( (int x) ) {
26 return x + 4;
27 } BOOST_LOCAL_FUNCTION_NAME(add2)
28
29 boost::function<int (int)> a2 = add2;
30 boost::function<int (int)> d2 = derivative(f&: a2, dx: 2);
31 BOOST_TEST(d2(6) == 1);
32 return boost::report_errors();
33}
34
35

source code of boost/libs/local_function/test/return_derivative_seq.cpp