You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

move.hpp 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. namespace ranges
  27. {
  28. /// \addtogroup group-algorithms
  29. /// @{
  30. template<typename I, typename O>
  31. using move_result = detail::in_out_result<I, O>;
  32. RANGES_HIDDEN_DETAIL(namespace _move CPP_PP_LBRACE())
  33. RANGES_BEGIN_NIEBLOID(move)
  34. /// \brief function template \c move
  35. template<typename I, typename S, typename O>
  36. auto RANGES_FUN_NIEBLOID(move)(I first, S last, O out) //
  37. ->CPP_ret(move_result<I, O>)( //
  38. requires input_iterator<I> && sentinel_for<S, I> &&
  39. weakly_incrementable<O> && indirectly_movable<I, O>)
  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. auto RANGES_FUN_NIEBLOID(move)(Rng && rng, O out) //
  48. ->CPP_ret(move_result<safe_iterator_t<Rng>, O>)( //
  49. requires input_range<Rng> && weakly_incrementable<O> &&
  50. indirectly_movable<iterator_t<Rng>, O>)
  51. {
  52. return (*this)(begin(rng), end(rng), std::move(out));
  53. }
  54. RANGES_END_NIEBLOID(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. #endif // include guard