Path: blob/main/contrib/llvm-project/libcxx/include/__algorithm/copy_n.h
35233 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___ALGORITHM_COPY_N_H9#define _LIBCPP___ALGORITHM_COPY_N_H1011#include <__algorithm/copy.h>12#include <__config>13#include <__iterator/iterator_traits.h>14#include <__type_traits/enable_if.h>15#include <__utility/convert_to_integral.h>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_BEGIN_NAMESPACE_STD2223template <class _InputIterator,24class _Size,25class _OutputIterator,26__enable_if_t<__has_input_iterator_category<_InputIterator>::value &&27!__has_random_access_iterator_category<_InputIterator>::value,28int> = 0>29inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator30copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {31typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;32_IntegralSize __n = __orig_n;33if (__n > 0) {34*__result = *__first;35++__result;36for (--__n; __n > 0; --__n) {37++__first;38*__result = *__first;39++__result;40}41}42return __result;43}4445template <class _InputIterator,46class _Size,47class _OutputIterator,48__enable_if_t<__has_random_access_iterator_category<_InputIterator>::value, int> = 0>49inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator50copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {51typedef typename iterator_traits<_InputIterator>::difference_type difference_type;52typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;53_IntegralSize __n = __orig_n;54return std::copy(__first, __first + difference_type(__n), __result);55}5657_LIBCPP_END_NAMESPACE_STD5859#endif // _LIBCPP___ALGORITHM_COPY_N_H606162