Skip to content

Commit 100ec87

Browse files
cjdbcopybara-github
authored andcommitted
[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. NOKEYCHECK=True GitOrigin-RevId: d10dc5a06fac4dcabf2264c64c8672c6f6ae36fb
1 parent 0eefee0 commit 100ec87

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

include/__algorithm/ranges_adjacent_find.h

Lines changed: 2 additions & 4 deletions
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

include/__algorithm/ranges_all_of.h

Lines changed: 2 additions & 4 deletions
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

include/__algorithm/ranges_any_of.h

Lines changed: 2 additions & 4 deletions
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

include/__algorithm/ranges_binary_search.h

Lines changed: 2 additions & 4 deletions
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

include/__algorithm/ranges_clamp.h

Lines changed: 2 additions & 4 deletions
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

include/__algorithm/ranges_contains.h

Lines changed: 2 additions & 4 deletions
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

include/__algorithm/ranges_contains_subrange.h

Lines changed: 2 additions & 4 deletions
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

include/__algorithm/ranges_copy.h

Lines changed: 2 additions & 4 deletions
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

include/__algorithm/ranges_copy_backward.h

Lines changed: 2 additions & 4 deletions
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

include/__algorithm/ranges_copy_if.h

Lines changed: 2 additions & 4 deletions
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

0 commit comments

Comments
 (0)