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 <algorithm>
16 #include <vector>
17 
main(void)18 int main(void) {
19     //[transform
20     int offset = 5;
21     std::vector<int> v;
22     std::vector<int> w;
23 
24     for(int i = 1; i <= 2; ++i) v.push_back(i * 10);
25     BOOST_TEST(v[0] == 10); BOOST_TEST(v[1] == 20);
26     w.resize(v.size());
27 
28     int BOOST_LOCAL_FUNCTION(const bind& offset, int i) {
29         return ++i + offset;
30     } BOOST_LOCAL_FUNCTION_NAME(inc)
31 
32     std::transform(v.begin(), v.end(), w.begin(), inc);
33     BOOST_TEST(w[0] == 16); BOOST_TEST(w[1] == 26);
34 
35     int BOOST_LOCAL_FUNCTION(bind& inc, int i, int j) {
36         return inc(i + j); // Call the other bound local function.
37     } BOOST_LOCAL_FUNCTION_NAME(inc_sum)
38 
39     offset = 0;
40     std::transform(v.begin(), v.end(), w.begin(), v.begin(), inc_sum);
41     BOOST_TEST(v[0] == 27); BOOST_TEST(v[1] == 47);
42     //]
43     return boost::report_errors();
44 }
45 
46 #endif // VARIADIC_MACROS
47 
48