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/detail/lightweight_test.hpp> 15 #include <vector> 16 #include <algorithm> 17 main(void)18int main(void) { 19 //[add_inline 20 int sum = 0, factor = 10; 21 22 void BOOST_LOCAL_FUNCTION(const bind factor, bind& sum, int num) { 23 sum += factor * num; 24 } BOOST_LOCAL_FUNCTION_NAME(inline add) // Inlining. 25 26 std::vector<int> v(100); 27 std::fill(v.begin(), v.end(), 1); 28 29 for(size_t i = 0; i < v.size(); ++i) add(v[i]); // Cannot use for_each. 30 //] 31 32 BOOST_TEST(sum == 1000); 33 return boost::report_errors(); 34 } 35 36 #endif // VARIADIC_MACROS 37 38