mem_fn_dm_test.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // mem_fn_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/mem_fn.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. int main()
  31. {
  32. X x = { 0 };
  33. boost::mem_fn( &X::m )( x ) = 401;
  34. BOOST_TEST( x.m == 401 );
  35. BOOST_TEST( boost::mem_fn( &X::m )( x ) == 401 );
  36. boost::mem_fn( &X::m )( &x ) = 502;
  37. BOOST_TEST( x.m == 502 );
  38. BOOST_TEST( boost::mem_fn( &X::m )( &x ) == 502 );
  39. X * px = &x;
  40. boost::mem_fn( &X::m )( px ) = 603;
  41. BOOST_TEST( x.m == 603 );
  42. BOOST_TEST( boost::mem_fn( &X::m )( px ) == 603 );
  43. X const & cx = x;
  44. X const * pcx = &x;
  45. BOOST_TEST( boost::mem_fn( &X::m )( cx ) == 603 );
  46. BOOST_TEST( boost::mem_fn( &X::m )( pcx ) == 603 );
  47. return boost::report_errors();
  48. }