return_setget_seq.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (C) 2009-2012 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0
  3. // (see accompanying file LICENSE_1_0.txt or a copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Home at http://www.boost.org/libs/local_function
  6. #include <boost/local_function.hpp>
  7. #include <boost/function.hpp>
  8. #include <boost/typeof/std/string.hpp>
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <string>
  11. boost::function<void (const std::string&)> set;
  12. boost::function<const std::string& (void)> get;
  13. void action(void) {
  14. BOOST_TEST(get() == "abc");
  15. set("xyz");
  16. BOOST_TEST(get() == "xyz");
  17. }
  18. int main(void) {
  19. std::string message = "abc";
  20. void BOOST_LOCAL_FUNCTION( (bind& message) (const std::string& text) ) {
  21. message = text;
  22. } BOOST_LOCAL_FUNCTION_NAME(s)
  23. set = s;
  24. const std::string& BOOST_LOCAL_FUNCTION( (const bind& message) ) {
  25. return message;
  26. } BOOST_LOCAL_FUNCTION_NAME(g)
  27. get = g;
  28. action();
  29. return boost::report_errors();
  30. }