Skip to content

Commit d10dc5a

Browse files
authored
[libc++] Remove dedicated namespaces for ranges functions (#76543)
We originally put implementation-detail function objects into individual namespaces for `std::ranges` without a good reason for doing so. This practice was continued, presumably because there was prior art. Since there's no reason to keep these namespaces, this commit removes them, which will slightly impact binary size. This commit does not apply to CPOs, some of which need additional work.
1 parent 3d1e1d9 commit d10dc5a

File tree

96 files changed

+255
-583
lines changed

Some content is hidden

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

96 files changed

+255
-583
lines changed

libcxx/include/__algorithm/ranges_adjacent_find.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS
3232
_LIBCPP_BEGIN_NAMESPACE_STD
3333

3434
namespace ranges {
35-
namespace __adjacent_find {
36-
struct __fn {
35+
struct __adjacent_find {
3736
template <class _Iter, class _Sent, class _Proj, class _Pred>
3837
_LIBCPP_HIDE_FROM_ABI constexpr static _Iter
3938
__adjacent_find_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
@@ -67,10 +66,9 @@ struct __fn {
6766
return __adjacent_find_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
6867
}
6968
};
70-
} // namespace __adjacent_find
7169

7270
inline namespace __cpo {
73-
inline constexpr auto adjacent_find = __adjacent_find::__fn{};
71+
inline constexpr auto adjacent_find = __adjacent_find{};
7472
} // namespace __cpo
7573
} // namespace ranges
7674

libcxx/include/__algorithm/ranges_all_of.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ _LIBCPP_PUSH_MACROS
3030
_LIBCPP_BEGIN_NAMESPACE_STD
3131

3232
namespace ranges {
33-
namespace __all_of {
34-
struct __fn {
33+
struct __all_of {
3534
template <class _Iter, class _Sent, class _Proj, class _Pred>
3635
_LIBCPP_HIDE_FROM_ABI constexpr static bool __all_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
3736
for (; __first != __last; ++__first) {
@@ -58,10 +57,9 @@ struct __fn {
5857
return __all_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
5958
}
6059
};
61-
} // namespace __all_of
6260

6361
inline namespace __cpo {
64-
inline constexpr auto all_of = __all_of::__fn{};
62+
inline constexpr auto all_of = __all_of{};
6563
} // namespace __cpo
6664
} // namespace ranges
6765

libcxx/include/__algorithm/ranges_any_of.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ _LIBCPP_PUSH_MACROS
3030
_LIBCPP_BEGIN_NAMESPACE_STD
3131

3232
namespace ranges {
33-
namespace __any_of {
34-
struct __fn {
33+
struct __any_of {
3534
template <class _Iter, class _Sent, class _Proj, class _Pred>
3635
_LIBCPP_HIDE_FROM_ABI constexpr static bool __any_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
3736
for (; __first != __last; ++__first) {
@@ -58,10 +57,9 @@ struct __fn {
5857
return __any_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
5958
}
6059
};
61-
} // namespace __any_of
6260

6361
inline namespace __cpo {
64-
inline constexpr auto any_of = __any_of::__fn{};
62+
inline constexpr auto any_of = __any_of{};
6563
} // namespace __cpo
6664
} // namespace ranges
6765

libcxx/include/__algorithm/ranges_binary_search.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS
3232
_LIBCPP_BEGIN_NAMESPACE_STD
3333

3434
namespace ranges {
35-
namespace __binary_search {
36-
struct __fn {
35+
struct __binary_search {
3736
template <forward_iterator _Iter,
3837
sentinel_for<_Iter> _Sent,
3938
class _Type,
@@ -57,10 +56,9 @@ struct __fn {
5756
return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret));
5857
}
5958
};
60-
} // namespace __binary_search
6159

6260
inline namespace __cpo {
63-
inline constexpr auto binary_search = __binary_search::__fn{};
61+
inline constexpr auto binary_search = __binary_search{};
6462
} // namespace __cpo
6563
} // namespace ranges
6664

libcxx/include/__algorithm/ranges_clamp.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ _LIBCPP_PUSH_MACROS
3030
_LIBCPP_BEGIN_NAMESPACE_STD
3131

3232
namespace ranges {
33-
namespace __clamp {
34-
struct __fn {
33+
struct __clamp {
3534
template <class _Type,
3635
class _Proj = identity,
3736
indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
@@ -50,10 +49,9 @@ struct __fn {
5049
return __value;
5150
}
5251
};
53-
} // namespace __clamp
5452

5553
inline namespace __cpo {
56-
inline constexpr auto clamp = __clamp::__fn{};
54+
inline constexpr auto clamp = __clamp{};
5755
} // namespace __cpo
5856
} // namespace ranges
5957

libcxx/include/__algorithm/ranges_contains.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ _LIBCPP_PUSH_MACROS
3333
_LIBCPP_BEGIN_NAMESPACE_STD
3434

3535
namespace ranges {
36-
namespace __contains {
37-
struct __fn {
36+
struct __contains {
3837
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
3938
requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
4039
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static
@@ -50,10 +49,9 @@ struct __fn {
5049
ranges::end(__range);
5150
}
5251
};
53-
} // namespace __contains
5452

5553
inline namespace __cpo {
56-
inline constexpr auto contains = __contains::__fn{};
54+
inline constexpr auto contains = __contains{};
5755
} // namespace __cpo
5856
} // namespace ranges
5957

libcxx/include/__algorithm/ranges_contains_subrange.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ _LIBCPP_PUSH_MACROS
3535
_LIBCPP_BEGIN_NAMESPACE_STD
3636

3737
namespace ranges {
38-
namespace __contains_subrange {
39-
struct __fn {
38+
struct __contains_subrange {
4039
template <forward_iterator _Iter1,
4140
sentinel_for<_Iter1> _Sent1,
4241
forward_iterator _Iter2,
@@ -81,10 +80,9 @@ struct __fn {
8180
return __ret.empty() == false;
8281
}
8382
};
84-
} // namespace __contains_subrange
8583

8684
inline namespace __cpo {
87-
inline constexpr auto contains_subrange = __contains_subrange::__fn{};
85+
inline constexpr auto contains_subrange = __contains_subrange{};
8886
} // namespace __cpo
8987
} // namespace ranges
9088

libcxx/include/__algorithm/ranges_copy.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ namespace ranges {
3737
template <class _InIter, class _OutIter>
3838
using copy_result = in_out_result<_InIter, _OutIter>;
3939

40-
namespace __copy {
41-
struct __fn {
40+
struct __copy {
4241
template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
4342
requires indirectly_copyable<_InIter, _OutIter>
4443
_LIBCPP_HIDE_FROM_ABI constexpr copy_result<_InIter, _OutIter>
@@ -55,10 +54,9 @@ struct __fn {
5554
return {std::move(__ret.first), std::move(__ret.second)};
5655
}
5756
};
58-
} // namespace __copy
5957

6058
inline namespace __cpo {
61-
inline constexpr auto copy = __copy::__fn{};
59+
inline constexpr auto copy = __copy{};
6260
} // namespace __cpo
6361
} // namespace ranges
6462

libcxx/include/__algorithm/ranges_copy_backward.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ namespace ranges {
3535
template <class _Ip, class _Op>
3636
using copy_backward_result = in_out_result<_Ip, _Op>;
3737

38-
namespace __copy_backward {
39-
struct __fn {
38+
struct __copy_backward {
4039
template <bidirectional_iterator _InIter1, sentinel_for<_InIter1> _Sent1, bidirectional_iterator _InIter2>
4140
requires indirectly_copyable<_InIter1, _InIter2>
4241
_LIBCPP_HIDE_FROM_ABI constexpr copy_backward_result<_InIter1, _InIter2>
@@ -53,10 +52,9 @@ struct __fn {
5352
return {std::move(__ret.first), std::move(__ret.second)};
5453
}
5554
};
56-
} // namespace __copy_backward
5755

5856
inline namespace __cpo {
59-
inline constexpr auto copy_backward = __copy_backward::__fn{};
57+
inline constexpr auto copy_backward = __copy_backward{};
6058
} // namespace __cpo
6159
} // namespace ranges
6260

libcxx/include/__algorithm/ranges_copy_if.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ namespace ranges {
3636
template <class _Ip, class _Op>
3737
using copy_if_result = in_out_result<_Ip, _Op>;
3838

39-
namespace __copy_if {
40-
struct __fn {
39+
struct __copy_if {
4140
template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
4241
_LIBCPP_HIDE_FROM_ABI static constexpr copy_if_result<_InIter, _OutIter>
4342
__copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
@@ -71,10 +70,9 @@ struct __fn {
7170
return __copy_if_impl(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj);
7271
}
7372
};
74-
} // namespace __copy_if
7573

7674
inline namespace __cpo {
77-
inline constexpr auto copy_if = __copy_if::__fn{};
75+
inline constexpr auto copy_if = __copy_if{};
7876
} // namespace __cpo
7977
} // namespace ranges
8078

libcxx/include/__algorithm/ranges_copy_n.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ namespace ranges {
3737
template <class _Ip, class _Op>
3838
using copy_n_result = in_out_result<_Ip, _Op>;
3939

40-
namespace __copy_n {
41-
struct __fn {
40+
struct __copy_n {
4241
template <class _InIter, class _DiffType, class _OutIter>
4342
_LIBCPP_HIDE_FROM_ABI constexpr static copy_n_result<_InIter, _OutIter>
4443
__go(_InIter __first, _DiffType __n, _OutIter __result) {
@@ -65,10 +64,9 @@ struct __fn {
6564
return __go(std::move(__first), __n, std::move(__result));
6665
}
6766
};
68-
} // namespace __copy_n
6967

7068
inline namespace __cpo {
71-
inline constexpr auto copy_n = __copy_n::__fn{};
69+
inline constexpr auto copy_n = __copy_n{};
7270
} // namespace __cpo
7371
} // namespace ranges
7472

libcxx/include/__algorithm/ranges_count.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ _LIBCPP_PUSH_MACROS
3434
_LIBCPP_BEGIN_NAMESPACE_STD
3535

3636
namespace ranges {
37-
namespace __count {
38-
struct __fn {
37+
struct __count {
3938
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
4039
requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
4140
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter>
@@ -50,10 +49,9 @@ struct __fn {
5049
return std::__count<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __proj);
5150
}
5251
};
53-
} // namespace __count
5452

5553
inline namespace __cpo {
56-
inline constexpr auto count = __count::__fn{};
54+
inline constexpr auto count = __count{};
5755
} // namespace __cpo
5856
} // namespace ranges
5957

libcxx/include/__algorithm/ranges_count_if.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ __count_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
4444
return __counter;
4545
}
4646

47-
namespace __count_if {
48-
struct __fn {
47+
struct __count_if {
4948
template <input_iterator _Iter,
5049
sentinel_for<_Iter> _Sent,
5150
class _Proj = identity,
@@ -63,10 +62,9 @@ struct __fn {
6362
return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
6463
}
6564
};
66-
} // namespace __count_if
6765

6866
inline namespace __cpo {
69-
inline constexpr auto count_if = __count_if::__fn{};
67+
inline constexpr auto count_if = __count_if{};
7068
} // namespace __cpo
7169
} // namespace ranges
7270

libcxx/include/__algorithm/ranges_ends_with.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ _LIBCPP_PUSH_MACROS
3636
_LIBCPP_BEGIN_NAMESPACE_STD
3737

3838
namespace ranges {
39-
namespace __ends_with {
40-
struct __fn {
39+
struct __ends_with {
4140
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
4241
_LIBCPP_HIDE_FROM_ABI static constexpr bool __ends_with_fn_impl_bidirectional(
4342
_Iter1 __first1,
@@ -185,10 +184,9 @@ struct __fn {
185184
}
186185
}
187186
};
188-
} // namespace __ends_with
189187

190188
inline namespace __cpo {
191-
inline constexpr auto ends_with = __ends_with::__fn{};
189+
inline constexpr auto ends_with = __ends_with{};
192190
} // namespace __cpo
193191
} // namespace ranges
194192

libcxx/include/__algorithm/ranges_equal.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ _LIBCPP_PUSH_MACROS
3434
_LIBCPP_BEGIN_NAMESPACE_STD
3535

3636
namespace ranges {
37-
namespace __equal {
38-
struct __fn {
37+
struct __equal {
3938
template <input_iterator _Iter1,
4039
sentinel_for<_Iter1> _Sent1,
4140
input_iterator _Iter2,
@@ -93,10 +92,9 @@ struct __fn {
9392
return false;
9493
}
9594
};
96-
} // namespace __equal
9795

9896
inline namespace __cpo {
99-
inline constexpr auto equal = __equal::__fn{};
97+
inline constexpr auto equal = __equal{};
10098
} // namespace __cpo
10199
} // namespace ranges
102100

libcxx/include/__algorithm/ranges_equal_range.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ _LIBCPP_PUSH_MACROS
3838
_LIBCPP_BEGIN_NAMESPACE_STD
3939

4040
namespace ranges {
41-
namespace __equal_range {
42-
43-
struct __fn {
41+
struct __equal_range {
4442
template <forward_iterator _Iter,
4543
sentinel_for<_Iter> _Sent,
4644
class _Tp,
@@ -64,10 +62,8 @@ struct __fn {
6462
}
6563
};
6664

67-
} // namespace __equal_range
68-
6965
inline namespace __cpo {
70-
inline constexpr auto equal_range = __equal_range::__fn{};
66+
inline constexpr auto equal_range = __equal_range{};
7167
} // namespace __cpo
7268
} // namespace ranges
7369

libcxx/include/__algorithm/ranges_fill.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ _LIBCPP_PUSH_MACROS
2828
_LIBCPP_BEGIN_NAMESPACE_STD
2929

3030
namespace ranges {
31-
namespace __fill {
32-
struct __fn {
31+
struct __fill {
3332
template <class _Type, output_iterator<const _Type&> _Iter, sentinel_for<_Iter> _Sent>
3433
_LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const {
3534
if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) {
@@ -46,10 +45,9 @@ struct __fn {
4645
return (*this)(ranges::begin(__range), ranges::end(__range), __value);
4746
}
4847
};
49-
} // namespace __fill
5048

5149
inline namespace __cpo {
52-
inline constexpr auto fill = __fill::__fn{};
50+
inline constexpr auto fill = __fill{};
5351
} // namespace __cpo
5452
} // namespace ranges
5553

libcxx/include/__algorithm/ranges_fill_n.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ _LIBCPP_PUSH_MACROS
2525
_LIBCPP_BEGIN_NAMESPACE_STD
2626

2727
namespace ranges {
28-
namespace __fill_n {
29-
struct __fn {
28+
struct __fill_n {
3029
template <class _Type, output_iterator<const _Type&> _Iter>
3130
_LIBCPP_HIDE_FROM_ABI constexpr _Iter
3231
operator()(_Iter __first, iter_difference_t<_Iter> __n, const _Type& __value) const {
@@ -37,10 +36,9 @@ struct __fn {
3736
return __first;
3837
}
3938
};
40-
} // namespace __fill_n
4139

4240
inline namespace __cpo {
43-
inline constexpr auto fill_n = __fill_n::__fn{};
41+
inline constexpr auto fill_n = __fill_n{};
4442
} // namespace __cpo
4543
} // namespace ranges
4644

0 commit comments

Comments
 (0)