Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

67 linhas
1.8KB

  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_COPY_N_HPP
  14. #define RANGES_V3_ALGORITHM_COPY_N_HPP
  15. #include <functional>
  16. #include <tuple>
  17. #include <utility>
  18. #include <range/v3/range_fwd.hpp>
  19. #include <range/v3/algorithm/result_types.hpp>
  20. #include <range/v3/functional/identity.hpp>
  21. #include <range/v3/iterator/concepts.hpp>
  22. #include <range/v3/iterator/operations.hpp>
  23. #include <range/v3/iterator/traits.hpp>
  24. #include <range/v3/range/access.hpp>
  25. #include <range/v3/range/concepts.hpp>
  26. #include <range/v3/range/traits.hpp>
  27. #include <range/v3/utility/static_const.hpp>
  28. namespace ranges
  29. {
  30. /// \addtogroup group-algorithms
  31. /// @{
  32. template<typename I, typename O>
  33. using copy_n_result = detail::in_out_result<I, O>;
  34. RANGES_BEGIN_NIEBLOID(copy_n)
  35. /// \brief function template \c copy_n
  36. template<typename I, typename O, typename P = identity>
  37. auto RANGES_FUN_NIEBLOID(copy_n)(I first, iter_difference_t<I> n, O out)
  38. ->CPP_ret(copy_n_result<I, O>)( //
  39. requires input_iterator<I> && weakly_incrementable<O> &&
  40. indirectly_copyable<I, O>)
  41. {
  42. RANGES_EXPECT(0 <= n);
  43. auto norig = n;
  44. auto b = uncounted(first);
  45. for(; n != 0; ++b, ++out, --n)
  46. *out = *b;
  47. return {recounted(first, b, norig), out};
  48. }
  49. RANGES_END_NIEBLOID(copy_n)
  50. namespace cpp20
  51. {
  52. using ranges::copy_n;
  53. using ranges::copy_n_result;
  54. } // namespace cpp20
  55. /// @}
  56. } // namespace ranges
  57. #endif // include guard