Wyrd

move_if_rr

Mar 26th, 2012
649
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <boost/mpl/if.hpp>
  2. #include <boost/mpl/not.hpp>
  3. #include <boost/mpl/or.hpp>
  4. #include <boost/type_traits/is_const.hpp>
  5. #include <boost/type_traits/is_reference.hpp>
  6. #include <boost/type_traits/remove_reference.hpp>
  7.  
  8. namespace Impl
  9. {
  10.     using namespace boost;
  11.  
  12.     //! Evaluates to true if T has move semantics inside forwarding function.
  13.     template< class T >
  14.     struct is_rr
  15.         :   mpl::not_< mpl::or_< is_reference< T >, is_const< typename remove_reference< T >::type > > >
  16.     {
  17.     };
  18.  
  19.     template< class U, class T >
  20.     struct move_if_rr_helper
  21.         :   mpl::if_< is_rr< U >, typename remove_reference< T >::type &&, T & >
  22.     {
  23.     };
  24. }
  25.  
  26. //! Moves rr if U && has move semantics inside forwarding function.
  27. template< class U, class T >
  28. inline typename Impl::move_if_rr_helper< U, T >::type move_if_rr( T &&rr )
  29. {
  30.     return static_cast< typename Impl::move_if_rr_helper< U, T >::type >( rr );
  31. }
RAW Paste Data