9
3

utility.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2012-2012.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/libs/move for documentation.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //! \file
  12. //! This header includes core utilities from <tt><boost/move/utility_core.hpp></tt> and defines
  13. //! some more advanced utilities such as:
  14. #ifndef BOOST_MOVE_MOVE_UTILITY_HPP
  15. #define BOOST_MOVE_MOVE_UTILITY_HPP
  16. #ifndef BOOST_CONFIG_HPP
  17. # include <boost/config.hpp>
  18. #endif
  19. #
  20. #if defined(BOOST_HAS_PRAGMA_ONCE)
  21. # pragma once
  22. #endif
  23. #include <boost/move/detail/config_begin.hpp>
  24. #include <boost/move/detail/workaround.hpp> //forceinline
  25. #include <boost/move/utility_core.hpp>
  26. #include <boost/move/traits.hpp>
  27. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED)
  28. namespace boost {
  29. //////////////////////////////////////////////////////////////////////////////
  30. //
  31. // move_if_noexcept()
  32. //
  33. //////////////////////////////////////////////////////////////////////////////
  34. template <class T>
  35. BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
  36. < enable_move_utility_emulation<T>::value && !has_move_emulation_enabled<T>::value
  37. , typename ::boost::move_detail::add_const<T>::type &
  38. >::type
  39. move_if_noexcept(T& x) BOOST_NOEXCEPT
  40. {
  41. return x;
  42. }
  43. template <class T>
  44. BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
  45. < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value
  46. && ::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value, rv<T>&>::type
  47. move_if_noexcept(T& x) BOOST_NOEXCEPT
  48. {
  49. return *static_cast<rv<T>* >(::boost::move_detail::addressof(x));
  50. }
  51. template <class T>
  52. BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
  53. < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value
  54. && ::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value
  55. , rv<T>&
  56. >::type
  57. move_if_noexcept(rv<T>& x) BOOST_NOEXCEPT
  58. {
  59. return x;
  60. }
  61. template <class T>
  62. BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
  63. < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value
  64. && !::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value
  65. , typename ::boost::move_detail::add_const<T>::type &
  66. >::type
  67. move_if_noexcept(T& x) BOOST_NOEXCEPT
  68. {
  69. return x;
  70. }
  71. template <class T>
  72. BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
  73. < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value
  74. && !::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value
  75. , typename ::boost::move_detail::add_const<T>::type &
  76. >::type
  77. move_if_noexcept(rv<T>& x) BOOST_NOEXCEPT
  78. {
  79. return x;
  80. }
  81. } //namespace boost
  82. #else //#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED)
  83. #if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
  84. #include <utility>
  85. namespace boost{
  86. using ::std::move_if_noexcept;
  87. } //namespace boost
  88. #else //!BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE
  89. namespace boost {
  90. //////////////////////////////////////////////////////////////////////////////
  91. //
  92. // move_if_noexcept()
  93. //
  94. //////////////////////////////////////////////////////////////////////////////
  95. #if defined(BOOST_MOVE_DOXYGEN_INVOKED)
  96. //! This function provides a way to convert a reference into a rvalue reference
  97. //! in compilers with rvalue references. For other compilers converts T & into
  98. //! <i>::boost::rv<T> &</i> so that move emulation is activated. Reference
  99. //! would be converted to rvalue reference only if input type is nothrow move
  100. //! constructible or if it has no copy constructor. In all other cases const
  101. //! reference would be returned
  102. template <class T>
  103. rvalue_reference_or_const_lvalue_reference move_if_noexcept(input_reference) noexcept;
  104. #else //BOOST_MOVE_DOXYGEN_INVOKED
  105. template <class T>
  106. BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
  107. < ::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value, T&&>::type
  108. move_if_noexcept(T& x) BOOST_NOEXCEPT
  109. { return ::boost::move(x); }
  110. template <class T>
  111. BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
  112. < !::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value, const T&>::type
  113. move_if_noexcept(T& x) BOOST_NOEXCEPT
  114. { return x; }
  115. #endif //BOOST_MOVE_DOXYGEN_INVOKED
  116. } //namespace boost {
  117. #endif //#if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
  118. #endif //BOOST_NO_CXX11_RVALUE_REFERENCES
  119. #include <boost/move/detail/config_end.hpp>
  120. #endif //#ifndef BOOST_MOVE_MOVE_UTILITY_HPP