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
18int 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(x: i * 10);
25 BOOST_TEST(v[0] == 10); BOOST_TEST(v[1] == 20);
26 w.resize(new_size: 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(first: v.begin(), last: v.end(), result: w.begin(), unary_op: 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(first1: v.begin(), last1: v.end(), first2: w.begin(), result: v.begin(), binary_op: 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

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