bind_dm1_test.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  22. #pragma warning(pop)
  23. #endif
  24. #include <boost/detail/lightweight_test.hpp>
  25. struct X
  26. {
  27. int m;
  28. };
  29. X f( int v )
  30. {
  31. X r = { v };
  32. return r;
  33. }
  34. int main()
  35. {
  36. using boost::phoenix::bind;
  37. using boost::phoenix::ref;
  38. using boost::phoenix::placeholders::_1;
  39. X x = { 17041 };
  40. X * px = &x;
  41. BOOST_TEST( bind( &X::m, _1 )( x ) == 17041 );
  42. BOOST_TEST( bind( &X::m, _1 )( px ) == 17041 );
  43. BOOST_TEST( bind( &X::m, x )() == 17041 );
  44. BOOST_TEST( bind( &X::m, px )() == 17041 );
  45. BOOST_TEST( bind( &X::m, ref(x) )() == 17041 );
  46. X const cx = x;
  47. X const * pcx = &cx;
  48. BOOST_TEST( bind( &X::m, _1 )( cx ) == 17041 );
  49. BOOST_TEST( bind( &X::m, _1 )( pcx ) == 17041 );
  50. BOOST_TEST( bind( &X::m, cx )() == 17041 );
  51. BOOST_TEST( bind( &X::m, pcx )() == 17041 );
  52. BOOST_TEST( bind( &X::m, ref(cx) )() == 17041 );
  53. int const v = 42;
  54. // Change bind_dm_test.cpp to bind to _1 twice.
  55. BOOST_TEST( bind( &X::m, _1)( bind( f, _1 )( v ) ) == v );
  56. return boost::report_errors();
  57. }