bind_rv_sp_test.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_rv_sp_test.cpp - smart pointer returned by value from an inner bind
  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/bind.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. #include <boost/shared_ptr.hpp>
  27. struct X
  28. {
  29. int v_;
  30. X( int v ): v_( v )
  31. {
  32. }
  33. int f()
  34. {
  35. return v_;
  36. }
  37. };
  38. struct Y
  39. {
  40. boost::shared_ptr<X> f()
  41. {
  42. return boost::shared_ptr<X>( new X( 42 ) );
  43. }
  44. };
  45. int main()
  46. {
  47. Y y;
  48. BOOST_TEST( boost::bind( &X::f, boost::bind( &Y::f, &y ) )() == 42 );
  49. return boost::report_errors();
  50. }