return_assign_seq.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include <iostream>
  10. void call1(boost::function<int (int) > f) { BOOST_TEST(f(1) == 5); }
  11. void call0(boost::function<int (void)> f) { BOOST_TEST(f() == 5); }
  12. boost::function<int (int, int)> linear(const int& slope) {
  13. int BOOST_LOCAL_FUNCTION( (const bind& slope)
  14. (int x)(default 1) (int y)(default 2) ) {
  15. return x + slope * y;
  16. } BOOST_LOCAL_FUNCTION_NAME(lin)
  17. boost::function<int (int, int)> f = lin;
  18. BOOST_TEST(f(1, 2) == 5);
  19. call1(lin);
  20. call0(lin);
  21. return lin;
  22. }
  23. void call(void) {
  24. boost::function<int (int, int)> f = linear(2);
  25. BOOST_TEST(f(1, 2) == 5);
  26. }
  27. int main(void) {
  28. call();
  29. return boost::report_errors();
  30. }