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/function.hpp>
15#include <boost/detail/lightweight_test.hpp>
16
17boost::function<int (void)> inc(int& value) {
18 int BOOST_LOCAL_FUNCTION(bind& value) {
19 return ++value;
20 } BOOST_LOCAL_FUNCTION_NAME(i)
21 return i;
22}
23
24int main(void) {
25 int value1 = 0; // Reference valid in scope where closure is used.
26 boost::function<int (void)> inc1 = inc(value&: value1);
27 int value2 = 0;
28 boost::function<int (void)> inc2 = inc(value&: value2);
29
30 BOOST_TEST(inc1() == 1);
31 BOOST_TEST(inc1() == 2);
32 BOOST_TEST(inc2() == 1);
33 BOOST_TEST(inc1() == 3);
34 return boost::report_errors();
35}
36
37#endif // VARIADIC_MACROS
38
39

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