bind_dm2_test.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_dm2_test.cpp - data members, advanced uses
  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. #include <string>
  23. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  24. #pragma warning(pop)
  25. #endif
  26. #include <boost/detail/lightweight_test.hpp>
  27. struct X
  28. {
  29. int m;
  30. };
  31. struct Y
  32. {
  33. char m[ 64 ];
  34. };
  35. int main()
  36. {
  37. X x = { 0 };
  38. X * px = &x;
  39. boost::bind< int& >( &X::m, _1 )( px ) = 42;
  40. BOOST_TEST( x.m == 42 );
  41. boost::bind< int& >( &X::m, boost::ref(x) )() = 17041;
  42. BOOST_TEST( x.m == 17041 );
  43. X const * pcx = &x;
  44. BOOST_TEST( boost::bind< long >( &X::m, _1 )( pcx ) == 17041L );
  45. BOOST_TEST( boost::bind< long >( &X::m, pcx )() == 17041L );
  46. Y y = { "test" };
  47. std::string v( "test" );
  48. BOOST_TEST( boost::bind< char const* >( &Y::m, &y )() == v );
  49. BOOST_TEST( boost::bind< std::string >( &Y::m, &y )() == v );
  50. return boost::report_errors();
  51. }