bind_dm2_test.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*==============================================================================
  2. Copyright (c) 2005 Peter Dimov
  3. Copyright (c) 2005-2010 Joel de Guzman
  4. Copyright (c) 2010 Thomas Heller
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #include <boost/config.hpp>
  9. #if defined(BOOST_MSVC)
  10. #pragma warning(disable: 4786) // identifier truncated in debug info
  11. #pragma warning(disable: 4710) // function not inlined
  12. #pragma warning(disable: 4711) // function selected for automatic inline expansion
  13. #pragma warning(disable: 4514) // unreferenced inline removed
  14. #endif
  15. #include <boost/phoenix/core.hpp>
  16. #include <boost/phoenix/bind.hpp>
  17. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  18. #pragma warning(push, 3)
  19. #endif
  20. #include <iostream>
  21. #include <string>
  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. struct Y
  31. {
  32. char m[ 64 ];
  33. };
  34. int main()
  35. {
  36. using boost::phoenix::bind;
  37. using boost::phoenix::ref;
  38. using boost::phoenix::placeholders::_1;
  39. X x = { 0 };
  40. X * px = &x;
  41. bind( &X::m, _1 )( px ) = 42;
  42. BOOST_TEST( x.m == 42 );
  43. bind( &X::m, ref(x) )() = 17041;
  44. BOOST_TEST( x.m == 17041 );
  45. X const * pcx = &x;
  46. BOOST_TEST( bind( &X::m, _1 )( pcx ) == 17041L );
  47. BOOST_TEST( bind( &X::m, pcx )() == 17041L );
  48. Y y = { "test" };
  49. std::string v( "test" );
  50. BOOST_TEST( bind( &Y::m, &y )() == v );
  51. BOOST_TEST( bind( &Y::m, &y )() == v );
  52. return boost::report_errors();
  53. }