return_inc_seq.cpp 853 B

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