algorithm.hpp 4.8 KB

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