bind_ref_test.cpp 670 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // bind_ref_test.cpp - reference_wrapper
  3. //
  4. // Copyright (c) 2009 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. //
  10. #include <boost/bind.hpp>
  11. #include <boost/ref.hpp>
  12. #include <boost/detail/lightweight_test.hpp>
  13. struct X
  14. {
  15. int f( int x )
  16. {
  17. return x;
  18. }
  19. int g( int x ) const
  20. {
  21. return -x;
  22. }
  23. };
  24. int main()
  25. {
  26. X x;
  27. BOOST_TEST( boost::bind( &X::f, _1, 1 )( boost::ref( x ) ) == 1 );
  28. BOOST_TEST( boost::bind( &X::g, _1, 2 )( boost::cref( x ) ) == -2 );
  29. return boost::report_errors();
  30. }