test_mixed_cxxstd.cpp 1005 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2018 Peter Dimov.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. #include <boost/function.hpp>
  4. #include <boost/core/lightweight_test.hpp>
  5. //
  6. void call_fn_1( boost::function<void()> const & fn );
  7. void call_fn_2( boost::function<void(int)> const & fn );
  8. void call_fn_3( boost::function<void(int, int)> const & fn );
  9. void call_fn_4( boost::function0<void> const & fn );
  10. void call_fn_5( boost::function1<void, int> const & fn );
  11. void call_fn_6( boost::function2<void, int, int> const & fn );
  12. //
  13. static int v;
  14. void f0()
  15. {
  16. v = -1;
  17. }
  18. void f1( int x )
  19. {
  20. v = x;
  21. }
  22. void f2( int x, int y )
  23. {
  24. v = x + y;
  25. }
  26. int main()
  27. {
  28. v = 0; call_fn_1( f0 ); BOOST_TEST_EQ( v, -1 );
  29. v = 0; call_fn_2( f1 ); BOOST_TEST_EQ( v, 1 );
  30. v = 0; call_fn_3( f2 ); BOOST_TEST_EQ( v, 3 );
  31. v = 0; call_fn_4( f0 ); BOOST_TEST_EQ( v, -1 );
  32. v = 0; call_fn_5( f1 ); BOOST_TEST_EQ( v, 1 );
  33. v = 0; call_fn_6( f2 ); BOOST_TEST_EQ( v, 3 );
  34. return boost::report_errors();
  35. }