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
12template<typename T>
13T total(const T& x, const T& y, const T& z) {
14 T sum = T(), factor = 10;
15
16 T BOOST_LOCAL_FUNCTION_TPL( (const bind factor) (bind& sum) (T num) ) {
17 return sum += factor * num;
18 } BOOST_LOCAL_FUNCTION_NAME_TPL(add)
19
20 add(x);
21 T nums[2]; nums[0] = y; nums[1] = z;
22 std::for_each(nums, nums + 2, add);
23
24 return sum;
25}
26
27int main(void) {
28 BOOST_TEST(total(1, 2, 3) == 60);
29 return boost::report_errors();
30}
31
32

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