move.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2014-present
  5. //
  6. // Use, modification and distribution is subject to the
  7. // Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // Project home: https://github.com/ericniebler/range-v3
  12. //
  13. #ifndef RANGES_V3_ALGORITHM_MOVE_HPP
  14. #define RANGES_V3_ALGORITHM_MOVE_HPP
  15. #include <utility>
  16. #include <range/v3/range_fwd.hpp>
  17. #include <range/v3/algorithm/result_types.hpp>
  18. #include <range/v3/iterator/concepts.hpp>
  19. #include <range/v3/iterator/traits.hpp>
  20. #include <range/v3/range/access.hpp>
  21. #include <range/v3/range/concepts.hpp>
  22. #include <range/v3/range/dangling.hpp>
  23. #include <range/v3/range/traits.hpp>
  24. #include <range/v3/utility/move.hpp>
  25. #include <range/v3/utility/static_const.hpp>
  26. #include <range/v3/detail/prologue.hpp>
  27. namespace ranges
  28. {
  29. /// \addtogroup group-algorithms
  30. /// @{
  31. template<typename I, typename O>
  32. using move_result = detail::in_out_result<I, O>;
  33. RANGES_HIDDEN_DETAIL(namespace _move CPP_PP_LBRACE())
  34. RANGES_FUNC_BEGIN(move)
  35. /// \brief function template \c move
  36. template(typename I, typename S, typename O)(
  37. requires input_iterator<I> AND sentinel_for<S, I> AND
  38. weakly_incrementable<O> AND indirectly_movable<I, O>)
  39. constexpr move_result<I, O> RANGES_FUNC(move)(I first, S last, O out) //
  40. {
  41. for(; first != last; ++first, ++out)
  42. *out = iter_move(first);
  43. return {first, out};
  44. }
  45. /// \overload
  46. template(typename Rng, typename O)(
  47. requires input_range<Rng> AND weakly_incrementable<O> AND
  48. indirectly_movable<iterator_t<Rng>, O>)
  49. constexpr move_result<borrowed_iterator_t<Rng>, O> //
  50. RANGES_FUNC(move)(Rng && rng, O out) //
  51. {
  52. return (*this)(begin(rng), end(rng), std::move(out));
  53. }
  54. RANGES_FUNC_END(move)
  55. RANGES_HIDDEN_DETAIL(CPP_PP_RBRACE())
  56. #ifndef RANGES_DOXYGEN_INVOKED
  57. struct RANGES_EMPTY_BASES move_fn
  58. : aux::move_fn
  59. , _move::move_fn
  60. {
  61. using aux::move_fn::operator();
  62. using _move::move_fn::operator();
  63. };
  64. RANGES_INLINE_VARIABLE(move_fn, move)
  65. #endif
  66. namespace cpp20
  67. {
  68. using ranges::move_result;
  69. using ranges::RANGES_HIDDEN_DETAIL(_move::) move;
  70. } // namespace cpp20
  71. /// @}
  72. } // namespace ranges
  73. #include <range/v3/detail/epilogue.hpp>
  74. #endif