Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:07

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_COPY_N_H
0010 #define _LIBCPP___ALGORITHM_COPY_N_H
0011 
0012 #include <__algorithm/copy.h>
0013 #include <__config>
0014 #include <__iterator/iterator_traits.h>
0015 #include <__type_traits/enable_if.h>
0016 #include <__utility/convert_to_integral.h>
0017 
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 #  pragma GCC system_header
0020 #endif
0021 
0022 _LIBCPP_BEGIN_NAMESPACE_STD
0023 
0024 template <class _InputIterator,
0025           class _Size,
0026           class _OutputIterator,
0027           __enable_if_t<__has_input_iterator_category<_InputIterator>::value &&
0028                             !__has_random_access_iterator_category<_InputIterator>::value,
0029                         int> = 0>
0030 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0031 copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
0032   typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
0033   _IntegralSize __n = __orig_n;
0034   if (__n > 0) {
0035     *__result = *__first;
0036     ++__result;
0037     for (--__n; __n > 0; --__n) {
0038       ++__first;
0039       *__result = *__first;
0040       ++__result;
0041     }
0042   }
0043   return __result;
0044 }
0045 
0046 template <class _InputIterator,
0047           class _Size,
0048           class _OutputIterator,
0049           __enable_if_t<__has_random_access_iterator_category<_InputIterator>::value, int> = 0>
0050 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0051 copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
0052   typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
0053   typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
0054   _IntegralSize __n = __orig_n;
0055   return std::copy(__first, __first + difference_type(__n), __result);
0056 }
0057 
0058 _LIBCPP_END_NAMESPACE_STD
0059 
0060 #endif // _LIBCPP___ALGORITHM_COPY_N_H