add_rvalue_reference.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_TYPE_TRAITS_EXT_ADD_RVALUE_REFERENCE__HPP
  6. #define BOOST_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. //----------------------------------------------------------------------------//
  12. // //
  13. // C++03 implementation of //
  14. // 20.9.7.2 Reference modifications [meta.trans.ref] //
  15. // Written by Vicente J. Botet Escriba //
  16. // //
  17. // If T names an object or function type then the member typedef type
  18. // shall name T&&; otherwise, type shall name T. [ Note: This rule reflects
  19. // the semantics of reference collapsing. For example, when a type T names
  20. // a type T1&, the type add_rvalue_reference<T>::type is not an rvalue
  21. // reference. -end note ]
  22. //----------------------------------------------------------------------------//
  23. namespace boost {
  24. namespace type_traits_detail {
  25. template <typename T, bool b>
  26. struct add_rvalue_reference_helper
  27. { typedef T type; };
  28. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  29. template <typename T>
  30. struct add_rvalue_reference_helper<T, true>
  31. {
  32. typedef T&& type;
  33. };
  34. #endif
  35. template <typename T>
  36. struct add_rvalue_reference_imp
  37. {
  38. typedef typename boost::type_traits_detail::add_rvalue_reference_helper
  39. <T, (is_void<T>::value == false && is_reference<T>::value == false) >::type type;
  40. };
  41. }
  42. template <class T> struct add_rvalue_reference
  43. {
  44. typedef typename boost::type_traits_detail::add_rvalue_reference_imp<T>::type type;
  45. };
  46. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  47. template <class T> using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
  48. #endif
  49. } // namespace boost
  50. #endif // BOOST_TYPE_TRAITS_EXT_ADD_RVALUE_REFERENCE__HPP