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/local_function.hpp>
9#include <boost/detail/lightweight_test.hpp>
10#include <algorithm>
11#include <vector>
12
13int main(void) {
14 int offset = 5;
15 std::vector<int> v;
16 std::vector<int> w;
17
18 for(int i = 1; i <= 2; ++i) v.push_back(x: i * 10);
19 BOOST_TEST(v[0] == 10); BOOST_TEST(v[1] == 20);
20 w.resize(new_size: v.size());
21
22 int BOOST_LOCAL_FUNCTION( (const bind& offset) (int i) ) {
23 return ++i + offset;
24 } BOOST_LOCAL_FUNCTION_NAME(inc)
25
26 std::transform(first: v.begin(), last: v.end(), result: w.begin(), unary_op: inc);
27 BOOST_TEST(w[0] == 16); BOOST_TEST(w[1] == 26);
28
29 int BOOST_LOCAL_FUNCTION( (bind& inc) (int i) (int j) ) {
30 return inc(i + j);
31 } BOOST_LOCAL_FUNCTION_NAME(inc_sum)
32
33 offset = 0;
34 std::transform(first1: v.begin(), last1: v.end(), first2: w.begin(), result: v.begin(), binary_op: inc_sum);
35 BOOST_TEST(v[0] == 27); BOOST_TEST(v[1] == 47);
36
37 return boost::report_errors();
38}
39
40

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