File indexing completed on 2026-05-03 08:13:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_FILL_N_H
0010 #define _LIBCPP___CXX03___ALGORITHM_FILL_N_H
0011
0012 #include <__cxx03/__algorithm/min.h>
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__fwd/bit_reference.h>
0015 #include <__cxx03/__iterator/iterator_traits.h>
0016 #include <__cxx03/__memory/pointer_traits.h>
0017 #include <__cxx03/__utility/convert_to_integral.h>
0018
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 # pragma GCC system_header
0021 #endif
0022
0023 _LIBCPP_PUSH_MACROS
0024 #include <__cxx03/__undef_macros>
0025
0026 _LIBCPP_BEGIN_NAMESPACE_STD
0027
0028
0029
0030 template <class _OutputIterator, class _Size, class _Tp>
0031 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0032 __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value);
0033
0034 template <bool _FillVal, class _Cp>
0035 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
0036 __fill_n_bool(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
0037 using _It = __bit_iterator<_Cp, false>;
0038 using __storage_type = typename _It::__storage_type;
0039
0040 const int __bits_per_word = _It::__bits_per_word;
0041
0042 if (__first.__ctz_ != 0) {
0043 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
0044 __storage_type __dn = std::min(__clz_f, __n);
0045 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
0046 if (_FillVal)
0047 *__first.__seg_ |= __m;
0048 else
0049 *__first.__seg_ &= ~__m;
0050 __n -= __dn;
0051 ++__first.__seg_;
0052 }
0053
0054 __storage_type __nw = __n / __bits_per_word;
0055 std::__fill_n(std::__to_address(__first.__seg_), __nw, _FillVal ? static_cast<__storage_type>(-1) : 0);
0056 __n -= __nw * __bits_per_word;
0057
0058 if (__n > 0) {
0059 __first.__seg_ += __nw;
0060 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
0061 if (_FillVal)
0062 *__first.__seg_ |= __m;
0063 else
0064 *__first.__seg_ &= ~__m;
0065 }
0066 }
0067
0068 template <class _Cp, class _Size>
0069 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false>
0070 __fill_n(__bit_iterator<_Cp, false> __first, _Size __n, const bool& __value) {
0071 if (__n > 0) {
0072 if (__value)
0073 std::__fill_n_bool<true>(__first, __n);
0074 else
0075 std::__fill_n_bool<false>(__first, __n);
0076 }
0077 return __first + __n;
0078 }
0079
0080 template <class _OutputIterator, class _Size, class _Tp>
0081 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0082 __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
0083 for (; __n > 0; ++__first, (void)--__n)
0084 *__first = __value;
0085 return __first;
0086 }
0087
0088 template <class _OutputIterator, class _Size, class _Tp>
0089 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0090 fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
0091 return std::__fill_n(__first, std::__convert_to_integral(__n), __value);
0092 }
0093
0094 _LIBCPP_END_NAMESPACE_STD
0095
0096 _LIBCPP_POP_MACROS
0097
0098 #endif