add_rvalue_reference.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // add_rvalue_reference.hpp ---------------------------------------------------------//
  2. // Copyright 2010 Vicente J. Botet Escriba
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. #ifndef BOOST_EX_TYPE_TRAITS_EXT_ADD_RVALUE_REFERENCE__HPP
  6. #define BOOST_EX_TYPE_TRAITS_EXT_ADD_RVALUE_REFERENCE__HPP
  7. #include <boost/config.hpp>
  8. //----------------------------------------------------------------------------//
  9. #include <boost/type_traits/is_void.hpp>
  10. #include <boost/type_traits/is_reference.hpp>
  11. // should be the last #include
  12. #include <boost/type_traits/detail/type_trait_def.hpp>
  13. //----------------------------------------------------------------------------//
  14. // //
  15. // C++03 implementation of //
  16. // 20.7.6.2 Reference modifications [meta.trans.ref] //
  17. // Written by Vicente J. Botet Escriba //
  18. // //
  19. // If T names an object or function type then the member typedef type
  20. // shall name T&&; otherwise, type shall name T. [ Note: This rule reflects
  21. // the semantics of reference collapsing. For example, when a type T names
  22. // a type T1&, the type add_rvalue_reference<T>::type is not an rvalue
  23. // reference. -end note ]
  24. //----------------------------------------------------------------------------//
  25. namespace boost_ex {
  26. namespace type_traits_detail {
  27. template <typename T, bool b>
  28. struct add_rvalue_reference_helper
  29. { typedef T type; };
  30. template <typename T>
  31. struct add_rvalue_reference_helper<T, true>
  32. {
  33. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  34. typedef T&& type;
  35. #else
  36. typedef T type;
  37. #endif
  38. };
  39. template <typename T>
  40. struct add_rvalue_reference_imp
  41. {
  42. typedef typename boost_ex::type_traits_detail::add_rvalue_reference_helper
  43. <T, (!boost::is_void<T>::value && !boost::is_reference<T>::value) >::type type;
  44. };
  45. }
  46. BOOST_TT_AUX_TYPE_TRAIT_DEF1(add_rvalue_reference,T,typename boost_ex::type_traits_detail::add_rvalue_reference_imp<T>::type)
  47. } // namespace boost_ex
  48. #include <boost/type_traits/detail/type_trait_undef.hpp>
  49. #endif // BOOST_EX_TYPE_TRAITS_EXT_ADD_RVALUE_REFERENCE__HPP