move.hpp 4.6 KB

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