bind_rv_sp4_test.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*==============================================================================
  2. Copyright (c) 2006 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. #include <boost/shared_ptr.hpp>
  26. struct X
  27. {
  28. int v_;
  29. X( int v ): v_( v )
  30. {
  31. }
  32. int f()
  33. {
  34. return v_;
  35. }
  36. };
  37. struct Y
  38. {
  39. boost::shared_ptr<X> f()
  40. {
  41. return boost::shared_ptr<X>( new X( 42 ) );
  42. }
  43. };
  44. int main()
  45. {
  46. using boost::phoenix::bind;
  47. //using boost::phoenix::placeholders::_1;
  48. Y y;
  49. // Change bind_rv_sp_test.cpp to bind to _1. Renamed f to g in y
  50. //BOOST_TEST( bind( &X::f, _1) ( bind( &Y::g, &y )()) == 42 );
  51. boost::shared_ptr<X> xp = bind( &Y::f, &y )();
  52. BOOST_TEST( bind( &X::f, xp)() == 42 );
  53. return boost::report_errors();
  54. }