brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 37732cc Raw
64 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___ALGORITHM_FILL_H10#define _LIBCPP___ALGORITHM_FILL_H11 12#include <__algorithm/fill_n.h>13#include <__algorithm/for_each_segment.h>14#include <__config>15#include <__iterator/iterator_traits.h>16#include <__iterator/segmented_iterator.h>17#include <__type_traits/enable_if.h>18#include <__type_traits/is_same.h>19 20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)21#  pragma GCC system_header22#endif23 24_LIBCPP_BEGIN_NAMESPACE_STD25 26// fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.27 28template <class _ForwardIterator, class _Sentinel, class _Tp>29inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator30__fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __value) {31#ifndef _LIBCPP_CXX03_LANG32  if constexpr (is_same<_ForwardIterator, _Sentinel>::value && __is_segmented_iterator_v<_ForwardIterator>) {33    using __local_iterator_t = typename __segmented_iterator_traits<_ForwardIterator>::__local_iterator;34    std::__for_each_segment(__first, __last, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) {35      std::__fill(__lfirst, __llast, __value);36    });37    return __last;38  }39#endif40  for (; __first != __last; ++__first)41    *__first = __value;42  return __first;43}44 45template <class _RandomAccessIterator,46          class _Tp,47          __enable_if_t<__has_random_access_iterator_category<_RandomAccessIterator>::value &&48                            !__is_segmented_iterator_v<_RandomAccessIterator>,49                        int> = 0>50inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator51__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value) {52  return std::__fill_n(__first, __last - __first, __value);53}54 55template <class _ForwardIterator, class _Tp>56inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void57fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {58  std::__fill(__first, __last, __value);59}60 61_LIBCPP_END_NAMESPACE_STD62 63#endif // _LIBCPP___ALGORITHM_FILL_H64