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.

copy_backward.hpp 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-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_COPY_BACKWARD_HPP
  14. #define RANGES_V3_ALGORITHM_COPY_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 copy_backward_result = detail::in_out_result<I, O>;
  32. RANGES_BEGIN_NIEBLOID(copy_backward)
  33. /// \brief function template \c copy_backward
  34. template<typename I, typename S, typename O>
  35. auto RANGES_FUN_NIEBLOID(copy_backward)(I first, S end_, O out)
  36. ->CPP_ret(copy_backward_result<I, O>)( //
  37. requires bidirectional_iterator<I> && sentinel_for<S, I> &&
  38. bidirectional_iterator<O> && indirectly_copyable<I, O>)
  39. {
  40. I i = ranges::next(first, end_), last = i;
  41. while(first != i)
  42. *--out = *--i;
  43. return {last, out};
  44. }
  45. /// \overload
  46. template<typename Rng, typename O>
  47. auto RANGES_FUN_NIEBLOID(copy_backward)(Rng && rng, O out)
  48. ->CPP_ret(copy_backward_result<safe_iterator_t<Rng>, O>)( //
  49. requires bidirectional_range<Rng> && bidirectional_iterator<O> &&
  50. indirectly_copyable<iterator_t<Rng>, O>)
  51. {
  52. return (*this)(begin(rng), end(rng), std::move(out));
  53. }
  54. RANGES_END_NIEBLOID(copy_backward)
  55. namespace cpp20
  56. {
  57. using ranges::copy_backward;
  58. using ranges::copy_backward_result;
  59. } // namespace cpp20
  60. /// @}
  61. } // namespace ranges
  62. #endif // include guard