Skip to content

Commit d89bca5

Browse files
committed
Fix circular reference
1 parent 86092be commit d89bca5

File tree

8 files changed

+160
-166
lines changed

8 files changed

+160
-166
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(files
1616
__algorithm/equal.h
1717
__algorithm/equal_range.h
1818
__algorithm/fill.h
19+
__algorithm/fill_fill_n_common.h
1920
__algorithm/fill_n.h
2021
__algorithm/find.h
2122
__algorithm/find_end.h
@@ -435,7 +436,6 @@ set(files
435436
__fwd/byte.h
436437
__fwd/complex.h
437438
__fwd/deque.h
438-
__fwd/fill.h
439439
__fwd/format.h
440440
__fwd/fstream.h
441441
__fwd/functional.h

libcxx/include/__algorithm/fill.h

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99
#ifndef _LIBCPP___ALGORITHM_FILL_H
1010
#define _LIBCPP___ALGORITHM_FILL_H
1111

12-
#include <__algorithm/fill_n.h>
13-
#include <__algorithm/for_each_segment.h>
12+
#include <__algorithm/fill_fill_n_common.h>
1413
#include <__config>
15-
#include <__iterator/iterator_traits.h>
16-
#include <__iterator/segmented_iterator.h>
17-
#include <__type_traits/enable_if.h>
1814

1915
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2016
# pragma GCC system_header
@@ -24,46 +20,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2420

2521
// fill isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
2622

27-
template <class _ForwardIterator,
28-
class _Sentinel,
29-
class _Tp,
30-
__enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
31-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
32-
__fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __value) {
33-
for (; __first != __last; ++__first)
34-
*__first = __value;
35-
}
36-
37-
template <class _OutIter, class _Tp>
38-
struct _FillSegment {
39-
using _Traits _LIBCPP_NODEBUG = __segmented_iterator_traits<_OutIter>;
40-
41-
const _Tp& __value_;
42-
43-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit _FillSegment(const _Tp& __value) : __value_(__value) {}
44-
45-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
46-
operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
47-
std::__fill(__lfirst, __llast, __value_);
48-
}
49-
};
50-
51-
template <class _RandomAccessIterator,
52-
class _Tp,
53-
__enable_if_t<__has_random_access_iterator_category<_RandomAccessIterator>::value &&
54-
!__is_segmented_iterator<_RandomAccessIterator>::value,
55-
int> >
56-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
57-
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value) {
58-
std::fill_n(__first, __last - __first, __value);
59-
}
60-
61-
template <class _SegmentedIterator, class _Tp, __enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> >
62-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
63-
__fill(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value) {
64-
std::__for_each_segment(__first, __last, _FillSegment<_SegmentedIterator, _Tp>(__value));
65-
}
66-
6723
template <class _ForwardIterator, class _Tp>
6824
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
6925
fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ALGORITHM_FILL_FILL_N_COMMON_H
10+
#define _LIBCPP___ALGORITHM_FILL_FILL_N_COMMON_H
11+
12+
#include <__algorithm/for_each_segment.h>
13+
#include <__algorithm/min.h>
14+
#include <__config>
15+
#include <__fwd/bit_reference.h>
16+
#include <__iterator/iterator_traits.h>
17+
#include <__iterator/next.h>
18+
#include <__iterator/segmented_iterator.h>
19+
#include <__memory/pointer_traits.h>
20+
#include <__type_traits/enable_if.h>
21+
#include <__utility/convert_to_integral.h>
22+
23+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24+
# pragma GCC system_header
25+
#endif
26+
27+
_LIBCPP_PUSH_MACROS
28+
#include <__undef_macros>
29+
30+
_LIBCPP_BEGIN_NAMESPACE_STD
31+
32+
template <class _ForwardIterator,
33+
class _Sentinel,
34+
class _Tp,
35+
__enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
36+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
37+
__fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __value);
38+
39+
template <class _RandomAccessIterator,
40+
class _Tp,
41+
__enable_if_t<__has_random_access_iterator_category<_RandomAccessIterator>::value &&
42+
!__is_segmented_iterator<_RandomAccessIterator>::value,
43+
int> = 0>
44+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
45+
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value);
46+
47+
template <class _SegmentedIterator,
48+
class _Tp,
49+
__enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
50+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
51+
__fill(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value);
52+
53+
template <class _OutIter, class _Size, class _Tp, __enable_if_t<!__is_segmented_iterator<_OutIter>::value, int> = 0>
54+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutIter
55+
__fill_n(_OutIter __first, _Size __n, const _Tp& __value) {
56+
for (; __n > 0; ++__first, (void)--__n)
57+
*__first = __value;
58+
return __first;
59+
}
60+
61+
template <bool _FillVal, class _Cp>
62+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
63+
__fill_n_bool(__bit_iterator<_Cp, false> __first, typename __size_difference_type_traits<_Cp>::size_type __n) {
64+
using _It = __bit_iterator<_Cp, false>;
65+
using __storage_type = typename _It::__storage_type;
66+
67+
const int __bits_per_word = _It::__bits_per_word;
68+
// do first partial word
69+
if (__first.__ctz_ != 0) {
70+
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
71+
__storage_type __dn = std::min(__clz_f, __n);
72+
std::__fill_masked_range(std::__to_address(__first.__seg_), __clz_f - __dn, __first.__ctz_, _FillVal);
73+
__n -= __dn;
74+
++__first.__seg_;
75+
}
76+
// do middle whole words
77+
__storage_type __nw = __n / __bits_per_word;
78+
std::__fill_n(std::__to_address(__first.__seg_), __nw, _FillVal ? static_cast<__storage_type>(-1) : 0);
79+
__n -= __nw * __bits_per_word;
80+
// do last partial word
81+
if (__n > 0) {
82+
__first.__seg_ += __nw;
83+
std::__fill_masked_range(std::__to_address(__first.__seg_), __bits_per_word - __n, 0u, _FillVal);
84+
}
85+
}
86+
87+
template <class _Cp, class _Size>
88+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false>
89+
__fill_n(__bit_iterator<_Cp, false> __first, _Size __n, const bool& __value) {
90+
if (__n > 0) {
91+
if (__value)
92+
std::__fill_n_bool<true>(__first, __n);
93+
else
94+
std::__fill_n_bool<false>(__first, __n);
95+
}
96+
return __first + __n;
97+
}
98+
99+
template < class _OutIter,
100+
class _Size,
101+
class _Tp,
102+
__enable_if_t<__is_segmented_iterator<_OutIter>::value && __has_forward_iterator_category<_OutIter>::value,
103+
int> = 0>
104+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _OutIter
105+
__fill_n(_OutIter __first, _Size __n, const _Tp& __value) {
106+
_OutIter __last = std::next(__first, __n);
107+
std::__fill(__first, __last, __value);
108+
return __last;
109+
}
110+
111+
template <class _ForwardIterator,
112+
class _Sentinel,
113+
class _Tp,
114+
__enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
115+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
116+
__fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __value) {
117+
for (; __first != __last; ++__first)
118+
*__first = __value;
119+
}
120+
121+
template <class _OutIter, class _Tp>
122+
struct _FillSegment {
123+
using _Traits _LIBCPP_NODEBUG = __segmented_iterator_traits<_OutIter>;
124+
125+
const _Tp& __value_;
126+
127+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit _FillSegment(const _Tp& __value) : __value_(__value) {}
128+
129+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
130+
operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
131+
std::__fill(__lfirst, __llast, __value_);
132+
}
133+
};
134+
135+
template <class _RandomAccessIterator,
136+
class _Tp,
137+
__enable_if_t<__has_random_access_iterator_category<_RandomAccessIterator>::value &&
138+
!__is_segmented_iterator<_RandomAccessIterator>::value,
139+
int> >
140+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
141+
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value) {
142+
std::__fill_n(__first, __last - __first, __value);
143+
}
144+
145+
template <class _SegmentedIterator, class _Tp, __enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> >
146+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
147+
__fill(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value) {
148+
std::__for_each_segment(__first, __last, _FillSegment<_SegmentedIterator, _Tp>(__value));
149+
}
150+
151+
_LIBCPP_END_NAMESPACE_STD
152+
153+
_LIBCPP_POP_MACROS
154+
155+
#endif // _LIBCPP___ALGORITHM_FILL_FILL_N_COMMON_H

libcxx/include/__algorithm/fill_n.h

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,18 @@
99
#ifndef _LIBCPP___ALGORITHM_FILL_N_H
1010
#define _LIBCPP___ALGORITHM_FILL_N_H
1111

12-
#include <__algorithm/min.h>
12+
#include <__algorithm/fill_fill_n_common.h>
1313
#include <__config>
14-
#include <__fwd/bit_reference.h>
15-
#include <__fwd/fill.h>
16-
#include <__iterator/iterator_traits.h>
17-
#include <__iterator/next.h>
18-
#include <__iterator/segmented_iterator.h>
19-
#include <__memory/pointer_traits.h>
20-
#include <__type_traits/enable_if.h>
2114
#include <__utility/convert_to_integral.h>
2215

2316
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2417
# pragma GCC system_header
2518
#endif
2619

27-
_LIBCPP_PUSH_MACROS
28-
#include <__undef_macros>
29-
3020
_LIBCPP_BEGIN_NAMESPACE_STD
3121

3222
// fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
3323

34-
template <class _OutIter, class _Size, class _Tp, __enable_if_t<!__is_segmented_iterator<_OutIter>::value, int> = 0>
35-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutIter
36-
__fill_n(_OutIter __first, _Size __n, const _Tp& __value) {
37-
for (; __n > 0; ++__first, (void)--__n)
38-
*__first = __value;
39-
return __first;
40-
}
41-
42-
template <bool _FillVal, class _Cp>
43-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
44-
__fill_n_bool(__bit_iterator<_Cp, false> __first, typename __size_difference_type_traits<_Cp>::size_type __n) {
45-
using _It = __bit_iterator<_Cp, false>;
46-
using __storage_type = typename _It::__storage_type;
47-
48-
const int __bits_per_word = _It::__bits_per_word;
49-
// do first partial word
50-
if (__first.__ctz_ != 0) {
51-
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
52-
__storage_type __dn = std::min(__clz_f, __n);
53-
std::__fill_masked_range(std::__to_address(__first.__seg_), __clz_f - __dn, __first.__ctz_, _FillVal);
54-
__n -= __dn;
55-
++__first.__seg_;
56-
}
57-
// do middle whole words
58-
__storage_type __nw = __n / __bits_per_word;
59-
std::__fill_n(std::__to_address(__first.__seg_), __nw, _FillVal ? static_cast<__storage_type>(-1) : 0);
60-
__n -= __nw * __bits_per_word;
61-
// do last partial word
62-
if (__n > 0) {
63-
__first.__seg_ += __nw;
64-
std::__fill_masked_range(std::__to_address(__first.__seg_), __bits_per_word - __n, 0u, _FillVal);
65-
}
66-
}
67-
68-
template <class _Cp, class _Size>
69-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false>
70-
__fill_n(__bit_iterator<_Cp, false> __first, _Size __n, const bool& __value) {
71-
if (__n > 0) {
72-
if (__value)
73-
std::__fill_n_bool<true>(__first, __n);
74-
else
75-
std::__fill_n_bool<false>(__first, __n);
76-
}
77-
return __first + __n;
78-
}
79-
80-
template < class _OutIter,
81-
class _Size,
82-
class _Tp,
83-
__enable_if_t<__is_segmented_iterator<_OutIter>::value && __has_forward_iterator_category<_OutIter>::value,
84-
int> = 0>
85-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _OutIter __fill_n(_OutIter __first, _Size __n, const _Tp& __value) {
86-
_OutIter __last = std::next(__first, __n);
87-
std::__fill(__first, __last, __value);
88-
return __last;
89-
}
90-
9124
template <class _OutputIterator, class _Size, class _Tp>
9225
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
9326
fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
@@ -96,6 +29,4 @@ fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
9629

9730
_LIBCPP_END_NAMESPACE_STD
9831

99-
_LIBCPP_POP_MACROS
100-
10132
#endif // _LIBCPP___ALGORITHM_FILL_N_H

libcxx/include/__algorithm/ranges_fill_n.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef _LIBCPP___ALGORITHM_RANGES_FILL_N_H
1010
#define _LIBCPP___ALGORITHM_RANGES_FILL_N_H
1111

12-
#include <__algorithm/fill_n.h>
12+
#include <__algorithm/fill_fill_n_common.h>
1313
#include <__config>
1414
#include <__iterator/concepts.h>
1515
#include <__iterator/incrementable_traits.h>

libcxx/include/__fwd/fill.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

libcxx/include/module.modulemap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ module std [system] {
424424
module count { header "__algorithm/count.h" }
425425
module equal_range { header "__algorithm/equal_range.h" }
426426
module equal { header "__algorithm/equal.h" }
427+
module fill_fill_n_common { header "__algorithm/fill_fill_n_common.h" }
427428
module fill_n { header "__algorithm/fill_n.h" }
428429
module fill { header "__algorithm/fill.h" }
429430
module find_end { header "__algorithm/find_end.h" }
@@ -435,7 +436,6 @@ module std [system] {
435436
module for_each_n { header "__algorithm/for_each_n.h" }
436437
module for_each_segment { header "__algorithm/for_each_segment.h" }
437438
module for_each { header "__algorithm/for_each.h" }
438-
module fwd { header "__fwd/fill.h" }
439439
module generate_n { header "__algorithm/generate_n.h" }
440440
module generate { header "__algorithm/generate.h" }
441441
module half_positive { header "__algorithm/half_positive.h" }

0 commit comments

Comments
 (0)