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/function.hpp> |
10 | #include <boost/detail/lightweight_test.hpp> |
11 | |
12 | boost::function<int (void)> inc(int& value) { |
13 | int BOOST_LOCAL_FUNCTION( (bind& value) ) { |
14 | return ++value; |
15 | } BOOST_LOCAL_FUNCTION_NAME(i) |
16 | return i; |
17 | } |
18 | |
19 | int main(void) { |
20 | int value1 = 0; |
21 | boost::function<int (void)> inc1 = inc(value&: value1); |
22 | int value2 = 0; |
23 | boost::function<int (void)> inc2 = inc(value&: value2); |
24 | |
25 | BOOST_TEST(inc1() == 1); |
26 | BOOST_TEST(inc1() == 2); |
27 | BOOST_TEST(inc2() == 1); |
28 | BOOST_TEST(inc1() == 3); |
29 | return boost::report_errors(); |
30 | } |
31 | |
32 |