bind_dm_test.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <boost/config.hpp>
  2. #if defined(BOOST_MSVC)
  3. #pragma warning(disable: 4786) // identifier truncated in debug info
  4. #pragma warning(disable: 4710) // function not inlined
  5. #pragma warning(disable: 4711) // function selected for automatic inline expansion
  6. #pragma warning(disable: 4514) // unreferenced inline removed
  7. #endif
  8. //
  9. // bind_dm_test.cpp - data members
  10. //
  11. // Copyright (c) 2005 Peter Dimov
  12. //
  13. // Distributed under the Boost Software License, Version 1.0. (See
  14. // accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt)
  16. //
  17. #include <boost/bind.hpp>
  18. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  19. #pragma warning(push, 3)
  20. #endif
  21. #include <iostream>
  22. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  23. #pragma warning(pop)
  24. #endif
  25. #include <boost/detail/lightweight_test.hpp>
  26. struct X
  27. {
  28. int m;
  29. };
  30. X f( int v )
  31. {
  32. X r = { v };
  33. return r;
  34. }
  35. int main()
  36. {
  37. X x = { 17041 };
  38. X * px = &x;
  39. BOOST_TEST( boost::bind( &X::m, _1 )( x ) == 17041 );
  40. BOOST_TEST( boost::bind( &X::m, _1 )( px ) == 17041 );
  41. BOOST_TEST( boost::bind( &X::m, x )() == 17041 );
  42. BOOST_TEST( boost::bind( &X::m, px )() == 17041 );
  43. BOOST_TEST( boost::bind( &X::m, boost::ref(x) )() == 17041 );
  44. X const cx = x;
  45. X const * pcx = &cx;
  46. BOOST_TEST( boost::bind( &X::m, _1 )( cx ) == 17041 );
  47. BOOST_TEST( boost::bind( &X::m, _1 )( pcx ) == 17041 );
  48. BOOST_TEST( boost::bind( &X::m, cx )() == 17041 );
  49. BOOST_TEST( boost::bind( &X::m, pcx )() == 17041 );
  50. BOOST_TEST( boost::bind( &X::m, boost::ref(cx) )() == 17041 );
  51. int const v = 42;
  52. BOOST_TEST( boost::bind( &X::m, boost::bind( f, _1 ) )( v ) == v );
  53. return boost::report_errors();
  54. }