45 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___CXX03___ALGORITHM_FILL_H10#define _LIBCPP___CXX03___ALGORITHM_FILL_H11 12#include <__cxx03/__algorithm/fill_n.h>13#include <__cxx03/__config>14#include <__cxx03/__iterator/iterator_traits.h>15 16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif19 20_LIBCPP_BEGIN_NAMESPACE_STD21 22// fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.23 24template <class _ForwardIterator, class _Tp>25inline _LIBCPP_HIDE_FROM_ABI void26__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag) {27 for (; __first != __last; ++__first)28 *__first = __value;29}30 31template <class _RandomAccessIterator, class _Tp>32inline _LIBCPP_HIDE_FROM_ABI void33__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag) {34 std::fill_n(__first, __last - __first, __value);35}36 37template <class _ForwardIterator, class _Tp>38inline _LIBCPP_HIDE_FROM_ABI void fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {39 std::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());40}41 42_LIBCPP_END_NAMESPACE_STD43 44#endif // _LIBCPP___CXX03___ALGORITHM_FILL_H45