// Copyright (C) 2009-2012 Lorenzo Caminiti // Distributed under the Boost Software License, Version 1.0 // (see accompanying file LICENSE_1_0.txt or a copy at // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/local_function #include #ifndef BOOST_NO_VARIADIC_MACROS #include #include #define BOOST_TEST_MODULE TestReturnDerivative #include boost::function derivative(boost::function& f, int dx) { int BOOST_LOCAL_FUNCTION(bind& f, const bind dx, int x) { return (f(x + dx) - f(x)) / dx; } BOOST_LOCAL_FUNCTION_NAME(deriv) return deriv; } BOOST_AUTO_TEST_CASE(test_return_derivative) { int BOOST_LOCAL_FUNCTION(int x) { return x + 4; } BOOST_LOCAL_FUNCTION_NAME(add2) boost::function a2 = add2; // Reference valid where closure used. boost::function d2 = derivative(a2, 2); BOOST_CHECK(d2(6) == 1); } #else int main(void) { return 0; } // Trivial test. #endif