Advertisement
Wyrd

boost shared_ptr move semantics test

Feb 22nd, 2012
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <tchar.h>
  2.  
  3. #define BOOST_HAS_RVALUE_REFS
  4.  
  5. #include <d:\Coding\MSVS 2010\VC\boost_1_48_0\boost\config\compiler\visualc.hpp>
  6. #include <d:\Coding\MSVS 2010\VC\boost_1_48_0\boost\shared_ptr.hpp>
  7. #include <d:\Coding\MSVS 2010\VC\boost_1_48_0\boost\make_shared.hpp>
  8.  
  9. class CBase
  10. {
  11. public:
  12.     virtual ~CBase()
  13.     {
  14.     }
  15. };
  16.  
  17. class CDerived
  18.     :   public CBase
  19. {
  20. };
  21.  
  22. namespace
  23. {
  24.     boost::shared_ptr< CBase > f()
  25.     {
  26.         auto pRes = boost::static_pointer_cast< CBase >( boost::make_shared< CDerived >() );
  27.         // ... Doing something with pRes
  28.         return std::move( pRes );
  29.     }
  30. }
  31.  
  32. int _tmain( int argc, _TCHAR* argv[] )
  33. {
  34.     auto p = f();
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement