Skip to content

Commit b872513

Browse files
ldionnecopybara-github
authored andcommitted
[libc++] Format the code base (#74334)
This patch runs clang-format on all of libcxx/include and libcxx/src, in accordance with the RFC discussed at [1]. Follow-up patches will format the benchmarks, the test suite and remaining parts of the code. I'm splitting this one into its own patch so the diff is a bit easier to review. This patch was generated with: find libcxx/include libcxx/src -type f \ | grep -v 'module.modulemap.in' \ | grep -v 'CMakeLists.txt' \ | grep -v 'README.txt' \ | grep -v 'libcxx.imp' \ | grep -v '__config_site.in' \ | xargs clang-format -i A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh to help resolve merge and rebase issues across these formatting changes. [1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all NOKEYCHECK=True GitOrigin-RevId: 9783f28cbb155e4a8d49c12e1c60ce14dcfaf0c7
1 parent d855d8b commit b872513

File tree

541 files changed

+67401
-84889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

541 files changed

+67401
-84889
lines changed

include/__algorithm/binary_search.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,16 @@
2222
_LIBCPP_BEGIN_NAMESPACE_STD
2323

2424
template <class _ForwardIterator, class _Tp, class _Compare>
25-
_LIBCPP_NODISCARD_EXT inline
26-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
27-
bool
28-
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
29-
{
30-
__first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
31-
return __first != __last && !__comp(__value, *__first);
25+
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
26+
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
27+
__first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
28+
return __first != __last && !__comp(__value, *__first);
3229
}
3330

3431
template <class _ForwardIterator, class _Tp>
35-
_LIBCPP_NODISCARD_EXT inline
36-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
37-
bool
38-
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
39-
{
40-
return std::binary_search(__first, __last, __value, __less<>());
32+
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
33+
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
34+
return std::binary_search(__first, __last, __value, __less<>());
4135
}
4236

4337
_LIBCPP_END_NAMESPACE_STD

include/__algorithm/comp_ref_type.h

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,42 @@
2020
_LIBCPP_BEGIN_NAMESPACE_STD
2121

2222
template <class _Compare>
23-
struct __debug_less
24-
{
25-
_Compare &__comp_;
26-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {}
23+
struct __debug_less {
24+
_Compare& __comp_;
25+
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {}
2726

28-
template <class _Tp, class _Up>
29-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
30-
bool operator()(const _Tp& __x, const _Up& __y)
31-
{
32-
bool __r = __comp_(__x, __y);
33-
if (__r)
34-
__do_compare_assert(0, __y, __x);
35-
return __r;
36-
}
27+
template <class _Tp, class _Up>
28+
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Up& __y) {
29+
bool __r = __comp_(__x, __y);
30+
if (__r)
31+
__do_compare_assert(0, __y, __x);
32+
return __r;
33+
}
3734

38-
template <class _Tp, class _Up>
39-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
40-
bool operator()(_Tp& __x, _Up& __y)
41-
{
42-
bool __r = __comp_(__x, __y);
43-
if (__r)
44-
__do_compare_assert(0, __y, __x);
45-
return __r;
46-
}
35+
template <class _Tp, class _Up>
36+
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(_Tp& __x, _Up& __y) {
37+
bool __r = __comp_(__x, __y);
38+
if (__r)
39+
__do_compare_assert(0, __y, __x);
40+
return __r;
41+
}
4742

48-
template <class _LHS, class _RHS>
49-
_LIBCPP_CONSTEXPR_SINCE_CXX14
50-
inline _LIBCPP_HIDE_FROM_ABI
51-
decltype((void)std::declval<_Compare&>()(
52-
std::declval<_LHS &>(), std::declval<_RHS &>()))
53-
__do_compare_assert(int, _LHS & __l, _RHS & __r) {
54-
_LIBCPP_ASSERT_UNCATEGORIZED(!__comp_(__l, __r),
55-
"Comparator does not induce a strict weak ordering");
56-
(void)__l;
57-
(void)__r;
58-
}
43+
template <class _LHS, class _RHS>
44+
_LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI decltype((void)std::declval<_Compare&>()(
45+
std::declval<_LHS&>(), std::declval<_RHS&>()))
46+
__do_compare_assert(int, _LHS& __l, _RHS& __r) {
47+
_LIBCPP_ASSERT_UNCATEGORIZED(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering");
48+
(void)__l;
49+
(void)__r;
50+
}
5951

60-
template <class _LHS, class _RHS>
61-
_LIBCPP_CONSTEXPR_SINCE_CXX14
62-
inline _LIBCPP_HIDE_FROM_ABI
63-
void __do_compare_assert(long, _LHS &, _RHS &) {}
52+
template <class _LHS, class _RHS>
53+
_LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI void __do_compare_assert(long, _LHS&, _RHS&) {}
6454
};
6555

6656
// Pass the comparator by lvalue reference. Or in debug mode, using a
6757
// debugging wrapper that stores a reference.
68-
# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
58+
#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
6959
template <class _Comp>
7060
using __comp_ref_type = __debug_less<_Comp>;
7161
#else

include/__algorithm/copy_backward.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ struct __copy_backward_loop {
108108

109109
struct __copy_backward_trivial {
110110
// At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
111-
template <class _In, class _Out,
112-
__enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
111+
template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
113112
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
114113
operator()(_In* __first, _In* __last, _Out* __result) const {
115114
return std::__copy_backward_trivial_impl(__first, __last, __result);
@@ -124,16 +123,13 @@ __copy_backward(_BidirectionalIterator1 __first, _Sentinel __last, _Bidirectiona
124123
}
125124

126125
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
127-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
128-
_BidirectionalIterator2
129-
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
130-
_BidirectionalIterator2 __result)
131-
{
126+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator2
127+
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) {
132128
static_assert(std::is_copy_constructible<_BidirectionalIterator1>::value &&
133-
std::is_copy_constructible<_BidirectionalIterator1>::value, "Iterators must be copy constructible.");
129+
std::is_copy_constructible<_BidirectionalIterator1>::value,
130+
"Iterators must be copy constructible.");
134131

135-
return std::__copy_backward<_ClassicAlgPolicy>(
136-
std::move(__first), std::move(__last), std::move(__result)).second;
132+
return std::__copy_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second;
137133
}
138134

139135
_LIBCPP_END_NAMESPACE_STD

include/__algorithm/copy_if.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@
1717

1818
_LIBCPP_BEGIN_NAMESPACE_STD
1919

20-
template<class _InputIterator, class _OutputIterator, class _Predicate>
21-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22-
_OutputIterator
23-
copy_if(_InputIterator __first, _InputIterator __last,
24-
_OutputIterator __result, _Predicate __pred)
25-
{
26-
for (; __first != __last; ++__first)
27-
{
28-
if (__pred(*__first))
29-
{
30-
*__result = *__first;
31-
++__result;
32-
}
20+
template <class _InputIterator, class _OutputIterator, class _Predicate>
21+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
22+
copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
23+
for (; __first != __last; ++__first) {
24+
if (__pred(*__first)) {
25+
*__result = *__first;
26+
++__result;
3327
}
34-
return __result;
28+
}
29+
return __result;
3530
}
3631

3732
_LIBCPP_END_NAMESPACE_STD

include/__algorithm/copy_move_common.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3838
template <class _From, class _To>
3939
struct __can_lower_copy_assignment_to_memmove {
4040
static const bool value =
41-
// If the types are always bitcastable, it's valid to do a bitwise copy between them.
42-
__is_always_bitcastable<_From, _To>::value &&
43-
// Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays).
44-
is_trivially_assignable<_To&, const _From&>::value &&
45-
// `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case.
46-
!is_volatile<_From>::value &&
47-
!is_volatile<_To>::value;
41+
// If the types are always bitcastable, it's valid to do a bitwise copy between them.
42+
__is_always_bitcastable<_From, _To>::value &&
43+
// Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays).
44+
is_trivially_assignable<_To&, const _From&>::value &&
45+
// `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case.
46+
!is_volatile<_From>::value && !is_volatile<_To>::value;
4847
};
4948

5049
template <class _From, class _To>
5150
struct __can_lower_move_assignment_to_memmove {
5251
static const bool value =
53-
__is_always_bitcastable<_From, _To>::value &&
54-
is_trivially_assignable<_To&, _From&&>::value &&
55-
!is_volatile<_From>::value &&
56-
!is_volatile<_To>::value;
52+
__is_always_bitcastable<_From, _To>::value && is_trivially_assignable<_To&, _From&&>::value &&
53+
!is_volatile<_From>::value && !is_volatile<_To>::value;
5754
};
5855

5956
// `memmove` algorithms implementation.
@@ -95,8 +92,8 @@ struct __can_rewrap<_InIter,
9592
_Sent,
9693
_OutIter,
9794
// Note that sentinels are always copy-constructible.
98-
__enable_if_t< is_copy_constructible<_InIter>::value &&
99-
is_copy_constructible<_OutIter>::value > > : true_type {};
95+
__enable_if_t< is_copy_constructible<_InIter>::value && is_copy_constructible<_OutIter>::value > >
96+
: true_type {};
10097

10198
template <class _Algorithm,
10299
class _InIter,
@@ -108,7 +105,7 @@ __unwrap_and_dispatch(_InIter __first, _Sent __last, _OutIter __out_first) {
108105
auto __range = std::__unwrap_range(__first, std::move(__last));
109106
auto __result = _Algorithm()(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__out_first));
110107
return std::make_pair(std::__rewrap_range<_Sent>(std::move(__first), std::move(__result.first)),
111-
std::__rewrap_iter(std::move(__out_first), std::move(__result.second)));
108+
std::__rewrap_iter(std::move(__out_first), std::move(__result.second)));
112109
}
113110

114111
template <class _Algorithm,

include/__algorithm/copy_n.h

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,38 @@
2121

2222
_LIBCPP_BEGIN_NAMESPACE_STD
2323

24-
template<class _InputIterator, class _Size, class _OutputIterator,
25-
__enable_if_t<__has_input_iterator_category<_InputIterator>::value &&
26-
!__has_random_access_iterator_category<_InputIterator>::value, int> = 0>
27-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
28-
_OutputIterator
29-
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
30-
{
31-
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
32-
_IntegralSize __n = __orig_n;
33-
if (__n > 0)
34-
{
35-
*__result = *__first;
36-
++__result;
37-
for (--__n; __n > 0; --__n)
38-
{
39-
++__first;
40-
*__result = *__first;
41-
++__result;
42-
}
24+
template <class _InputIterator,
25+
class _Size,
26+
class _OutputIterator,
27+
__enable_if_t<__has_input_iterator_category<_InputIterator>::value &&
28+
!__has_random_access_iterator_category<_InputIterator>::value,
29+
int> = 0>
30+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
31+
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
32+
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
33+
_IntegralSize __n = __orig_n;
34+
if (__n > 0) {
35+
*__result = *__first;
36+
++__result;
37+
for (--__n; __n > 0; --__n) {
38+
++__first;
39+
*__result = *__first;
40+
++__result;
4341
}
44-
return __result;
42+
}
43+
return __result;
4544
}
4645

47-
template<class _InputIterator, class _Size, class _OutputIterator,
48-
__enable_if_t<__has_random_access_iterator_category<_InputIterator>::value, int> = 0>
49-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
50-
_OutputIterator
51-
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
52-
{
53-
typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
54-
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
55-
_IntegralSize __n = __orig_n;
56-
return std::copy(__first, __first + difference_type(__n), __result);
46+
template <class _InputIterator,
47+
class _Size,
48+
class _OutputIterator,
49+
__enable_if_t<__has_random_access_iterator_category<_InputIterator>::value, int> = 0>
50+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
51+
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) {
52+
typedef typename iterator_traits<_InputIterator>::difference_type difference_type;
53+
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
54+
_IntegralSize __n = __orig_n;
55+
return std::copy(__first, __first + difference_type(__n), __result);
5756
}
5857

5958
_LIBCPP_END_NAMESPACE_STD

include/__algorithm/equal.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
6868
#if _LIBCPP_STD_VER >= 14
6969
template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2>
7070
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
71-
__equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
72-
_BinaryPredicate __pred, input_iterator_tag, input_iterator_tag) {
71+
__equal(_InputIterator1 __first1,
72+
_InputIterator1 __last1,
73+
_InputIterator2 __first2,
74+
_InputIterator2 __last2,
75+
_BinaryPredicate __pred,
76+
input_iterator_tag,
77+
input_iterator_tag) {
7378
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void)++__first2)
7479
if (!__pred(*__first1, *__first2))
7580
return false;
@@ -104,8 +109,12 @@ __equal_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&,
104109

105110
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
106111
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
107-
__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
108-
_RandomAccessIterator2 __last2, _BinaryPredicate __pred, random_access_iterator_tag,
112+
__equal(_RandomAccessIterator1 __first1,
113+
_RandomAccessIterator1 __last1,
114+
_RandomAccessIterator2 __first2,
115+
_RandomAccessIterator2 __last2,
116+
_BinaryPredicate __pred,
117+
random_access_iterator_tag,
109118
random_access_iterator_tag) {
110119
if (std::distance(__first1, __last1) != std::distance(__first2, __last2))
111120
return false;
@@ -122,10 +131,18 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Random
122131

123132
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
124133
_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
125-
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
134+
equal(_InputIterator1 __first1,
135+
_InputIterator1 __last1,
136+
_InputIterator2 __first2,
137+
_InputIterator2 __last2,
126138
_BinaryPredicate __pred) {
127139
return std::__equal<_BinaryPredicate&>(
128-
__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_InputIterator1>::iterator_category(),
140+
__first1,
141+
__last1,
142+
__first2,
143+
__last2,
144+
__pred,
145+
typename iterator_traits<_InputIterator1>::iterator_category(),
129146
typename iterator_traits<_InputIterator2>::iterator_category());
130147
}
131148

include/__algorithm/equal_range.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
4949
__len = __half_len;
5050
} else {
5151
_Iter __mp1 = __mid;
52-
return pair<_Iter, _Iter>(
53-
std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
54-
std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
52+
return pair<_Iter, _Iter>(std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
53+
std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
5554
}
5655
}
5756
return pair<_Iter, _Iter>(__first, __first);
@@ -60,10 +59,8 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
6059
template <class _ForwardIterator, class _Tp, class _Compare>
6160
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
6261
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
63-
static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value,
64-
"The comparator has to be callable");
65-
static_assert(is_copy_constructible<_ForwardIterator>::value,
66-
"Iterator has to be copy constructible");
62+
static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
63+
static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible");
6764
return std::__equal_range<_ClassicAlgPolicy>(
6865
std::move(__first),
6966
std::move(__last),

0 commit comments

Comments
 (0)