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/typeof/std/string.hpp>
11 #include <boost/detail/lightweight_test.hpp>
12 #include <string>
13 
14 boost::function<void (const std::string&)> set;
15 boost::function<const std::string& (void)> get;
16 
action(void)17 void action(void) {
18     BOOST_TEST(get() == "abc");
19     set("xyz");
20     BOOST_TEST(get() == "xyz");
21 }
22 
main(void)23 int main(void) {
24     std::string message = "abc";
25 
26     void BOOST_LOCAL_FUNCTION( (bind& message) (const std::string& text) ) {
27         message = text;
28     } BOOST_LOCAL_FUNCTION_NAME(s)
29     set = s;
30 
31     const std::string& BOOST_LOCAL_FUNCTION( (const bind& message) ) {
32         return message;
33     } BOOST_LOCAL_FUNCTION_NAME(g)
34     get = g;
35 
36     action();
37     return boost::report_errors();
38 }
39 
40