bind_void_dm_test.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_void_mf_test.cpp - test for bind<void> with member functions
  10. //
  11. // Copyright (c) 2008 Peter Dimov
  12. // Copyright (c) 2014 Agustin Berge
  13. //
  14. // Distributed under the Boost Software License, Version 1.0. (See
  15. // accompanying file LICENSE_1_0.txt or copy at
  16. // http://www.boost.org/LICENSE_1_0.txt)
  17. //
  18. #include <boost/bind.hpp>
  19. #include <boost/ref.hpp>
  20. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  21. #pragma warning(push, 3)
  22. #endif
  23. #include <iostream>
  24. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  25. #pragma warning(pop)
  26. #endif
  27. #include <boost/detail/lightweight_test.hpp>
  28. //
  29. struct Z
  30. {
  31. int m;
  32. };
  33. void member_data_test()
  34. {
  35. Z z = { 17041 };
  36. Z * pz = &z;
  37. boost::bind<void>( &Z::m, _1 )( z );
  38. boost::bind<void>( &Z::m, _1 )( pz );
  39. boost::bind<void>( &Z::m, z )();
  40. boost::bind<void>( &Z::m, pz )();
  41. boost::bind<void>( &Z::m, boost::ref(z) )();
  42. Z const cz = z;
  43. Z const * pcz = &cz;
  44. boost::bind<void>( &Z::m, _1 )( cz );
  45. boost::bind<void>( &Z::m, _1 )( pcz );
  46. boost::bind<void>( &Z::m, cz )();
  47. boost::bind<void>( &Z::m, pcz )();
  48. boost::bind<void>( &Z::m, boost::ref(cz) )();
  49. }
  50. int main()
  51. {
  52. member_data_test();
  53. return boost::report_errors();
  54. }