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/phoenix.hpp>
9#include <boost/detail/lightweight_test.hpp>
10#include <algorithm>
11#include <iostream>
12
13//[add_phoenix
14int main(void) {
15 using boost::phoenix::let;
16 using boost::phoenix::local_names::_f;
17 using boost::phoenix::cref;
18 using boost::phoenix::ref;
19 using boost::phoenix::arg_names::_1;
20
21 int sum = 0, factor = 10;
22 int nums[] = {1, 2, 3};
23
24 // Passed to template, `factor` by constant, and defined in expression.
25 std::for_each(first: nums, last: nums + 3, f: let(a: _f = cref(t: factor))[
26 // Unfortunately, body cannot use C++ statement syntax.
27 ( ref(t&: sum) += _f * _1, _1 ) // Access `sum` by reference.
28 ]);
29
30 BOOST_TEST(sum == 60);
31 return boost::report_errors();
32}
33//]
34
35

source code of boost/libs/local_function/example/add_phoenix.cpp