Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

73 lines
2.3KB

  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_BACKWARD_HPP
  14. #define RANGES_V3_ALGORITHM_MOVE_BACKWARD_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/operations.hpp>
  20. #include <range/v3/iterator/traits.hpp>
  21. #include <range/v3/range/access.hpp>
  22. #include <range/v3/range/concepts.hpp>
  23. #include <range/v3/range/dangling.hpp>
  24. #include <range/v3/range/traits.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_backward_result = detail::in_out_result<I, O>;
  32. RANGES_BEGIN_NIEBLOID(move_backward)
  33. /// \brief function template \c move_backward
  34. template<typename I, typename S, typename O>
  35. auto RANGES_FUN_NIEBLOID(move_backward)(I first, S end_, O out) //
  36. ->CPP_ret(move_backward_result<I, O>)( //
  37. requires bidirectional_iterator<I> && sentinel_for<S, I> &&
  38. bidirectional_iterator<O> && indirectly_movable<I, O>)
  39. {
  40. I i = ranges::next(first, end_), last = i;
  41. while(first != i)
  42. *--out = iter_move(--i);
  43. return {last, out};
  44. }
  45. /// \overload
  46. template<typename Rng, typename O>
  47. auto RANGES_FUN_NIEBLOID(move_backward)(Rng && rng, O out) //
  48. ->CPP_ret(move_backward_result<safe_iterator_t<Rng>, O>)( //
  49. requires bidirectional_range<Rng> && bidirectional_iterator<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_backward)
  55. namespace cpp20
  56. {
  57. using ranges::move_backward;
  58. using ranges::move_backward_result;
  59. } // namespace cpp20
  60. /// @}
  61. } // namespace ranges
  62. #endif // include guard