algorithm.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #ifndef BOOST_MOVE_ALGORITHM_HPP
  13. #define BOOST_MOVE_ALGORITHM_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/iterator.hpp>
  24. #include <boost/move/algo/move.hpp>
  25. #include <algorithm> //copy, copy_backward
  26. #include <memory> //uninitialized_copy
  27. namespace boost {
  28. //////////////////////////////////////////////////////////////////////////////
  29. //
  30. // uninitialized_copy_or_move
  31. //
  32. //////////////////////////////////////////////////////////////////////////////
  33. namespace move_detail {
  34. template
  35. <typename I, // I models InputIterator
  36. typename F> // F models ForwardIterator
  37. inline F uninitialized_move_move_iterator(I f, I l, F r
  38. // ,typename ::boost::move_detail::enable_if< has_move_emulation_enabled<typename I::value_type> >::type* = 0
  39. )
  40. {
  41. return ::boost::uninitialized_move(f, l, r);
  42. }
  43. /*
  44. template
  45. <typename I, // I models InputIterator
  46. typename F> // F models ForwardIterator
  47. F uninitialized_move_move_iterator(I f, I l, F r,
  48. typename ::boost::move_detail::disable_if< has_move_emulation_enabled<typename I::value_type> >::type* = 0)
  49. {
  50. return std::uninitialized_copy(f.base(), l.base(), r);
  51. }
  52. */
  53. } //namespace move_detail {
  54. template
  55. <typename I, // I models InputIterator
  56. typename F> // F models ForwardIterator
  57. inline F uninitialized_copy_or_move(I f, I l, F r,
  58. typename ::boost::move_detail::enable_if< move_detail::is_move_iterator<I> >::type* = 0)
  59. {
  60. return ::boost::move_detail::uninitialized_move_move_iterator(f, l, r);
  61. }
  62. //////////////////////////////////////////////////////////////////////////////
  63. //
  64. // copy_or_move
  65. //
  66. //////////////////////////////////////////////////////////////////////////////
  67. namespace move_detail {
  68. template
  69. <typename I, // I models InputIterator
  70. typename F> // F models ForwardIterator
  71. inline F move_move_iterator(I f, I l, F r
  72. // ,typename ::boost::move_detail::enable_if< has_move_emulation_enabled<typename I::value_type> >::type* = 0
  73. )
  74. {
  75. return ::boost::move(f, l, r);
  76. }
  77. /*
  78. template
  79. <typename I, // I models InputIterator
  80. typename F> // F models ForwardIterator
  81. F move_move_iterator(I f, I l, F r,
  82. typename ::boost::move_detail::disable_if< has_move_emulation_enabled<typename I::value_type> >::type* = 0)
  83. {
  84. return std::copy(f.base(), l.base(), r);
  85. }
  86. */
  87. } //namespace move_detail {
  88. template
  89. <typename I, // I models InputIterator
  90. typename F> // F models ForwardIterator
  91. inline F copy_or_move(I f, I l, F r,
  92. typename ::boost::move_detail::enable_if< move_detail::is_move_iterator<I> >::type* = 0)
  93. {
  94. return ::boost::move_detail::move_move_iterator(f, l, r);
  95. }
  96. /// @endcond
  97. //! <b>Effects</b>:
  98. //! \code
  99. //! for (; first != last; ++result, ++first)
  100. //! new (static_cast<void*>(&*result))
  101. //! typename iterator_traits<ForwardIterator>::value_type(*first);
  102. //! \endcode
  103. //!
  104. //! <b>Returns</b>: result
  105. //!
  106. //! <b>Note</b>: This function is provided because
  107. //! <i>std::uninitialized_copy</i> from some STL implementations
  108. //! is not compatible with <i>move_iterator</i>
  109. template
  110. <typename I, // I models InputIterator
  111. typename F> // F models ForwardIterator
  112. inline F uninitialized_copy_or_move(I f, I l, F r
  113. /// @cond
  114. ,typename ::boost::move_detail::disable_if< move_detail::is_move_iterator<I> >::type* = 0
  115. /// @endcond
  116. )
  117. {
  118. return std::uninitialized_copy(f, l, r);
  119. }
  120. //! <b>Effects</b>:
  121. //! \code
  122. //! for (; first != last; ++result, ++first)
  123. //! *result = *first;
  124. //! \endcode
  125. //!
  126. //! <b>Returns</b>: result
  127. //!
  128. //! <b>Note</b>: This function is provided because
  129. //! <i>std::uninitialized_copy</i> from some STL implementations
  130. //! is not compatible with <i>move_iterator</i>
  131. template
  132. <typename I, // I models InputIterator
  133. typename F> // F models ForwardIterator
  134. inline F copy_or_move(I f, I l, F r
  135. /// @cond
  136. ,typename ::boost::move_detail::disable_if< move_detail::is_move_iterator<I> >::type* = 0
  137. /// @endcond
  138. )
  139. {
  140. return std::copy(f, l, r);
  141. }
  142. } //namespace boost {
  143. #include <boost/move/detail/config_end.hpp>
  144. #endif //#ifndef BOOST_MOVE_ALGORITHM_HPP