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
8 #include <boost/config.hpp>
9 #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
10 # error "variadic macros required"
13 #include <boost/local_function.hpp>
14 #include <boost/detail/lightweight_test.hpp>
20 adder(void) : sum_(0) {}
22 int sum(const std::vector<int>& nums, const int& factor = 10) {
23 // Explicitly specify bound variable and return types (no type-of).
24 BOOST_LOCAL_FUNCTION(const bind(const int&) factor,
25 bind(adder*) this_, int num, return int) {
26 return this_->sum_ += factor * num;
27 } BOOST_LOCAL_FUNCTION_NAME(add)
29 std::for_each(nums.begin(), nums.end(), add);
39 std::vector<int> v(3);
40 v[0] = 1; v[1] = 2; v[2] = 3;
42 BOOST_TEST(adder().sum(v) == 60);
43 return boost::report_errors();
46 #endif // VARIADIC_MACROS