move.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2012-2016.
  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. #ifndef BOOST_MOVE_ALGO_MOVE_HPP
  13. #define BOOST_MOVE_ALGO_MOVE_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #
  18. #if defined(BOOST_HAS_PRAGMA_ONCE)
  19. # pragma once
  20. #endif
  21. #include <boost/move/detail/config_begin.hpp>
  22. #include <boost/move/utility_core.hpp>
  23. #include <boost/move/detail/iterator_traits.hpp>
  24. #include <boost/detail/no_exceptions_support.hpp>
  25. namespace boost {
  26. //////////////////////////////////////////////////////////////////////////////
  27. //
  28. // move
  29. //
  30. //////////////////////////////////////////////////////////////////////////////
  31. #if !defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
  32. //! <b>Effects</b>: Moves elements in the range [first,last) into the range [result,result + (last -
  33. //! first)) starting from first and proceeding to last. For each non-negative integer n < (last-first),
  34. //! performs *(result + n) = ::boost::move (*(first + n)).
  35. //!
  36. //! <b>Effects</b>: result + (last - first).
  37. //!
  38. //! <b>Requires</b>: result shall not be in the range [first,last).
  39. //!
  40. //! <b>Complexity</b>: Exactly last - first move assignments.
  41. template <typename I, // I models InputIterator
  42. typename O> // O models OutputIterator
  43. O move(I f, I l, O result)
  44. {
  45. while (f != l) {
  46. *result = ::boost::move(*f);
  47. ++f; ++result;
  48. }
  49. return result;
  50. }
  51. //////////////////////////////////////////////////////////////////////////////
  52. //
  53. // move_backward
  54. //
  55. //////////////////////////////////////////////////////////////////////////////
  56. //! <b>Effects</b>: Moves elements in the range [first,last) into the range
  57. //! [result - (last-first),result) starting from last - 1 and proceeding to
  58. //! first. For each positive integer n <= (last - first),
  59. //! performs *(result - n) = ::boost::move(*(last - n)).
  60. //!
  61. //! <b>Requires</b>: result shall not be in the range [first,last).
  62. //!
  63. //! <b>Returns</b>: result - (last - first).
  64. //!
  65. //! <b>Complexity</b>: Exactly last - first assignments.
  66. template <typename I, // I models BidirectionalIterator
  67. typename O> // O models BidirectionalIterator
  68. O move_backward(I f, I l, O result)
  69. {
  70. while (f != l) {
  71. --l; --result;
  72. *result = ::boost::move(*l);
  73. }
  74. return result;
  75. }
  76. #else
  77. using ::std::move_backward;
  78. #endif //!defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
  79. //////////////////////////////////////////////////////////////////////////////
  80. //
  81. // uninitialized_move
  82. //
  83. //////////////////////////////////////////////////////////////////////////////
  84. //! <b>Effects</b>:
  85. //! \code
  86. //! for (; first != last; ++result, ++first)
  87. //! new (static_cast<void*>(&*result))
  88. //! typename iterator_traits<ForwardIterator>::value_type(boost::move(*first));
  89. //! \endcode
  90. //!
  91. //! <b>Returns</b>: result
  92. template
  93. <typename I, // I models InputIterator
  94. typename F> // F models ForwardIterator
  95. F uninitialized_move(I f, I l, F r
  96. /// @cond
  97. // ,typename ::boost::move_detail::enable_if<has_move_emulation_enabled<typename boost::movelib::iterator_traits<I>::value_type> >::type* = 0
  98. /// @endcond
  99. )
  100. {
  101. typedef typename boost::movelib::iterator_traits<I>::value_type input_value_type;
  102. F back = r;
  103. BOOST_TRY{
  104. while (f != l) {
  105. void * const addr = static_cast<void*>(::boost::move_detail::addressof(*r));
  106. ::new(addr) input_value_type(::boost::move(*f));
  107. ++f; ++r;
  108. }
  109. }
  110. BOOST_CATCH(...){
  111. for (; back != r; ++back){
  112. back->~input_value_type();
  113. }
  114. BOOST_RETHROW;
  115. }
  116. BOOST_CATCH_END
  117. return r;
  118. }
  119. /// @cond
  120. /*
  121. template
  122. <typename I, // I models InputIterator
  123. typename F> // F models ForwardIterator
  124. F uninitialized_move(I f, I l, F r,
  125. typename ::boost::move_detail::disable_if<has_move_emulation_enabled<typename boost::movelib::iterator_traits<I>::value_type> >::type* = 0)
  126. {
  127. return std::uninitialized_copy(f, l, r);
  128. }
  129. */
  130. /// @endcond
  131. } //namespace boost {
  132. #include <boost/move/detail/config_end.hpp>
  133. #endif //#ifndef BOOST_MOVE_ALGO_MOVE_HPP