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.hpp 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_HPP
  14. #define RANGES_V3_ALGORITHM_COPY_HPP
  15. #include <functional>
  16. #include <utility>
  17. #include <range/v3/range_fwd.hpp>
  18. #include <range/v3/algorithm/result_types.hpp>
  19. #include <range/v3/iterator/concepts.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/copy.hpp>
  26. #include <range/v3/utility/static_const.hpp>
  27. namespace ranges
  28. {
  29. /// \addtogroup group-algorithms
  30. /// @{
  31. template<typename I, typename O>
  32. using copy_result = detail::in_out_result<I, O>;
  33. RANGES_HIDDEN_DETAIL(namespace _copy CPP_PP_LBRACE())
  34. RANGES_BEGIN_NIEBLOID(copy)
  35. /// \brief function template \c copy
  36. template<typename I, typename S, typename O>
  37. constexpr auto RANGES_FUN_NIEBLOID(copy)(I first, S last, O out) //
  38. ->CPP_ret(copy_result<I, O>)( //
  39. requires input_iterator<I> && sentinel_for<S, I> &&
  40. weakly_incrementable<O> && indirectly_copyable<I, O>)
  41. {
  42. for(; first != last; ++first, ++out)
  43. *out = *first;
  44. return {first, out};
  45. } // namespace ranges
  46. /// \overload
  47. template<typename Rng, typename O>
  48. constexpr auto RANGES_FUN_NIEBLOID(copy)(Rng && rng, O out) //
  49. ->CPP_ret(copy_result<safe_iterator_t<Rng>, O>)( //
  50. requires input_range<Rng> && weakly_incrementable<O> &&
  51. indirectly_copyable<iterator_t<Rng>, O>)
  52. {
  53. return (*this)(begin(rng), end(rng), std::move(out));
  54. }
  55. RANGES_END_NIEBLOID(copy)
  56. RANGES_HIDDEN_DETAIL(CPP_PP_RBRACE())
  57. #ifndef RANGES_DOXYGEN_INVOKED
  58. struct copy_fn
  59. : aux::copy_fn
  60. , _copy::copy_fn
  61. {
  62. using aux::copy_fn::operator();
  63. using _copy::copy_fn::operator();
  64. };
  65. RANGES_INLINE_VARIABLE(copy_fn, copy)
  66. #endif
  67. namespace cpp20
  68. {
  69. using ranges::copy_result;
  70. using ranges::RANGES_HIDDEN_DETAIL(_copy::) copy;
  71. } // namespace cpp20
  72. /// @}
  73. } // namespace ranges
  74. #endif // include guard