Skip to content

[libcxx] removes dedicated namespaces for ranges stuff #76543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

cjdb
Copy link
Contributor

@cjdb cjdb commented Dec 28, 2023

I originally put implementation-detail function objects into individual namespaces for std::ranges without a good reason for doing so. This practice was continued after I left libc++, 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.

@cjdb cjdb added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 28, 2023
@cjdb cjdb requested review from lnihlen and var-const December 28, 2023 23:52
@cjdb cjdb requested a review from a team as a code owner December 28, 2023 23:52
@llvmbot
Copy link
Member

llvmbot commented Dec 28, 2023

@llvm/pr-subscribers-libcxx

Author: Christopher Di Bella (cjdb)

Changes

I originally put implementation-detail function objects into individual namespaces for std::ranges without a good reason for doing so. This practice was continued after I left libc++, 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.


Patch is 94.38 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/76543.diff

94 Files Affected:

  • (modified) libcxx/include/__algorithm/ranges_adjacent_find.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_all_of.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_any_of.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_binary_search.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_clamp.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_contains.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_copy.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_copy_backward.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_copy_if.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_copy_n.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_count.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_count_if.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_ends_with.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_equal.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_equal_range.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_fill.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_fill_n.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_find.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_find_end.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_find_first_of.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_find_if.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_find_if_not.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_for_each.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_for_each_n.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_generate.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_generate_n.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_includes.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_inplace_merge.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_is_heap.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_is_heap_until.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_is_partitioned.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_is_permutation.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_is_sorted.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_is_sorted_until.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_lexicographical_compare.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_lower_bound.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_make_heap.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_max.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_max_element.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_merge.h (+35-39)
  • (modified) libcxx/include/__algorithm/ranges_min.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_min_element.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_minmax.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_minmax_element.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_mismatch.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_move.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_move_backward.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_next_permutation.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_none_of.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_nth_element.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_partial_sort.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_partial_sort_copy.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_partition.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_partition_copy.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_partition_point.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_pop_heap.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_prev_permutation.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_push_heap.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_remove.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_remove_copy.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_remove_copy_if.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_remove_if.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_replace.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_replace_copy.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_replace_copy_if.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_replace_if.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_reverse.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_reverse_copy.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_rotate.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_rotate_copy.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_sample.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_search.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_search_n.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_set_difference.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_set_intersection.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_set_symmetric_difference.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_set_union.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_shuffle.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_sort.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_sort_heap.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_stable_partition.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_stable_sort.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_starts_with.h (+4-6)
  • (modified) libcxx/include/__algorithm/ranges_swap_ranges.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_transform.h (+2-4)
  • (modified) libcxx/include/__algorithm/ranges_unique.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_unique_copy.h (+2-6)
  • (modified) libcxx/include/__algorithm/ranges_upper_bound.h (+2-4)
  • (modified) libcxx/include/__iterator/advance.h (+2-6)
  • (modified) libcxx/include/__iterator/distance.h (+2-6)
  • (modified) libcxx/include/__iterator/next.h (+2-6)
  • (modified) libcxx/include/__iterator/prev.h (+2-6)
  • (modified) libcxx/include/__memory/ranges_construct_at.h (+8-24)
  • (modified) libcxx/include/__memory/ranges_uninitialized_algorithms.h (+20-60)
diff --git a/libcxx/include/__algorithm/ranges_adjacent_find.h b/libcxx/include/__algorithm/ranges_adjacent_find.h
index a10b04167ede69..a4938cdd79b2ae 100644
--- a/libcxx/include/__algorithm/ranges_adjacent_find.h
+++ b/libcxx/include/__algorithm/ranges_adjacent_find.h
@@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __adjacent_find {
-struct __fn {
+struct __adjacent_find {
   template <class _Iter, class _Sent, class _Proj, class _Pred>
   _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
   __adjacent_find_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
@@ -67,10 +66,9 @@ struct __fn {
     return __adjacent_find_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
   }
 };
-} // namespace __adjacent_find
 
 inline namespace __cpo {
-inline constexpr auto adjacent_find = __adjacent_find::__fn{};
+inline constexpr auto adjacent_find = __adjacent_find{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_all_of.h b/libcxx/include/__algorithm/ranges_all_of.h
index 39a2ae4de01e99..9d4ed2a0ce4127 100644
--- a/libcxx/include/__algorithm/ranges_all_of.h
+++ b/libcxx/include/__algorithm/ranges_all_of.h
@@ -27,8 +27,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __all_of {
-struct __fn {
+struct __all_of {
   template <class _Iter, class _Sent, class _Proj, class _Pred>
   _LIBCPP_HIDE_FROM_ABI constexpr static bool __all_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
     for (; __first != __last; ++__first) {
@@ -55,10 +54,9 @@ struct __fn {
     return __all_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
   }
 };
-} // namespace __all_of
 
 inline namespace __cpo {
-inline constexpr auto all_of = __all_of::__fn{};
+inline constexpr auto all_of = __all_of{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_any_of.h b/libcxx/include/__algorithm/ranges_any_of.h
index 2ca8531102eac6..a7b48b9f622262 100644
--- a/libcxx/include/__algorithm/ranges_any_of.h
+++ b/libcxx/include/__algorithm/ranges_any_of.h
@@ -27,8 +27,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __any_of {
-struct __fn {
+struct __any_of {
   template <class _Iter, class _Sent, class _Proj, class _Pred>
   _LIBCPP_HIDE_FROM_ABI constexpr static bool __any_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
     for (; __first != __last; ++__first) {
@@ -55,10 +54,9 @@ struct __fn {
     return __any_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
   }
 };
-} // namespace __any_of
 
 inline namespace __cpo {
-inline constexpr auto any_of = __any_of::__fn{};
+inline constexpr auto any_of = __any_of{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_binary_search.h b/libcxx/include/__algorithm/ranges_binary_search.h
index 22008e0f1bc8f6..193b2358d4a6ca 100644
--- a/libcxx/include/__algorithm/ranges_binary_search.h
+++ b/libcxx/include/__algorithm/ranges_binary_search.h
@@ -29,8 +29,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __binary_search {
-struct __fn {
+struct __binary_search {
   template <forward_iterator _Iter,
             sentinel_for<_Iter> _Sent,
             class _Type,
@@ -54,10 +53,9 @@ struct __fn {
     return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret));
   }
 };
-} // namespace __binary_search
 
 inline namespace __cpo {
-inline constexpr auto binary_search = __binary_search::__fn{};
+inline constexpr auto binary_search = __binary_search{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_clamp.h b/libcxx/include/__algorithm/ranges_clamp.h
index e6c86207254a19..373488b7b50ed8 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -27,8 +27,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __clamp {
-struct __fn {
+struct __clamp {
   template <class _Type,
             class _Proj                                                      = identity,
             indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
@@ -46,10 +45,9 @@ struct __fn {
       return __value;
   }
 };
-} // namespace __clamp
 
 inline namespace __cpo {
-inline constexpr auto clamp = __clamp::__fn{};
+inline constexpr auto clamp = __clamp{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_contains.h b/libcxx/include/__algorithm/ranges_contains.h
index f92fcec587d858..f2156ad76109ba 100644
--- a/libcxx/include/__algorithm/ranges_contains.h
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -30,8 +30,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __contains {
-struct __fn {
+struct __contains {
   template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
     requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
   _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool static
@@ -47,10 +46,9 @@ struct __fn {
            ranges::end(__range);
   }
 };
-} // namespace __contains
 
 inline namespace __cpo {
-inline constexpr auto contains = __contains::__fn{};
+inline constexpr auto contains = __contains{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_copy.h b/libcxx/include/__algorithm/ranges_copy.h
index 1c87f074e7cab9..d3450528ca1820 100644
--- a/libcxx/include/__algorithm/ranges_copy.h
+++ b/libcxx/include/__algorithm/ranges_copy.h
@@ -34,8 +34,7 @@ namespace ranges {
 template <class _InIter, class _OutIter>
 using copy_result = in_out_result<_InIter, _OutIter>;
 
-namespace __copy {
-struct __fn {
+struct __copy {
   template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
     requires indirectly_copyable<_InIter, _OutIter>
   _LIBCPP_HIDE_FROM_ABI constexpr copy_result<_InIter, _OutIter>
@@ -52,10 +51,9 @@ struct __fn {
     return {std::move(__ret.first), std::move(__ret.second)};
   }
 };
-} // namespace __copy
 
 inline namespace __cpo {
-inline constexpr auto copy = __copy::__fn{};
+inline constexpr auto copy = __copy{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_copy_backward.h b/libcxx/include/__algorithm/ranges_copy_backward.h
index 865e944d4384dd..6122313bcb9224 100644
--- a/libcxx/include/__algorithm/ranges_copy_backward.h
+++ b/libcxx/include/__algorithm/ranges_copy_backward.h
@@ -32,8 +32,7 @@ namespace ranges {
 template <class _Ip, class _Op>
 using copy_backward_result = in_out_result<_Ip, _Op>;
 
-namespace __copy_backward {
-struct __fn {
+struct __copy_backward {
   template <bidirectional_iterator _InIter1, sentinel_for<_InIter1> _Sent1, bidirectional_iterator _InIter2>
     requires indirectly_copyable<_InIter1, _InIter2>
   _LIBCPP_HIDE_FROM_ABI constexpr copy_backward_result<_InIter1, _InIter2>
@@ -50,10 +49,9 @@ struct __fn {
     return {std::move(__ret.first), std::move(__ret.second)};
   }
 };
-} // namespace __copy_backward
 
 inline namespace __cpo {
-inline constexpr auto copy_backward = __copy_backward::__fn{};
+inline constexpr auto copy_backward = __copy_backward{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_copy_if.h b/libcxx/include/__algorithm/ranges_copy_if.h
index b77dbd37fcee3a..e57d3964518c2a 100644
--- a/libcxx/include/__algorithm/ranges_copy_if.h
+++ b/libcxx/include/__algorithm/ranges_copy_if.h
@@ -33,8 +33,7 @@ namespace ranges {
 template <class _Ip, class _Op>
 using copy_if_result = in_out_result<_Ip, _Op>;
 
-namespace __copy_if {
-struct __fn {
+struct __copy_if {
   template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
   _LIBCPP_HIDE_FROM_ABI static constexpr copy_if_result<_InIter, _OutIter>
   __copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
@@ -68,10 +67,9 @@ struct __fn {
     return __copy_if_impl(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj);
   }
 };
-} // namespace __copy_if
 
 inline namespace __cpo {
-inline constexpr auto copy_if = __copy_if::__fn{};
+inline constexpr auto copy_if = __copy_if{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_copy_n.h b/libcxx/include/__algorithm/ranges_copy_n.h
index 99e8eee14d0f83..c9678a29c3585f 100644
--- a/libcxx/include/__algorithm/ranges_copy_n.h
+++ b/libcxx/include/__algorithm/ranges_copy_n.h
@@ -34,8 +34,7 @@ namespace ranges {
 template <class _Ip, class _Op>
 using copy_n_result = in_out_result<_Ip, _Op>;
 
-namespace __copy_n {
-struct __fn {
+struct __copy_n {
   template <class _InIter, class _DiffType, class _OutIter>
   _LIBCPP_HIDE_FROM_ABI constexpr static copy_n_result<_InIter, _OutIter>
   __go(_InIter __first, _DiffType __n, _OutIter __result) {
@@ -62,10 +61,9 @@ struct __fn {
     return __go(std::move(__first), __n, std::move(__result));
   }
 };
-} // namespace __copy_n
 
 inline namespace __cpo {
-inline constexpr auto copy_n = __copy_n::__fn{};
+inline constexpr auto copy_n = __copy_n{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_count.h b/libcxx/include/__algorithm/ranges_count.h
index 4c8f1b2cbea7e4..ad36c4345539cc 100644
--- a/libcxx/include/__algorithm/ranges_count.h
+++ b/libcxx/include/__algorithm/ranges_count.h
@@ -31,8 +31,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __count {
-struct __fn {
+struct __count {
   template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
     requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
   _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter>
@@ -47,10 +46,9 @@ struct __fn {
     return std::__count<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __proj);
   }
 };
-} // namespace __count
 
 inline namespace __cpo {
-inline constexpr auto count = __count::__fn{};
+inline constexpr auto count = __count{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_count_if.h b/libcxx/include/__algorithm/ranges_count_if.h
index 92f37d049e0c4d..1ed564bfd65824 100644
--- a/libcxx/include/__algorithm/ranges_count_if.h
+++ b/libcxx/include/__algorithm/ranges_count_if.h
@@ -41,8 +41,7 @@ __count_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
   return __counter;
 }
 
-namespace __count_if {
-struct __fn {
+struct __count_if {
   template <input_iterator _Iter,
             sentinel_for<_Iter> _Sent,
             class _Proj = identity,
@@ -60,10 +59,9 @@ struct __fn {
     return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
   }
 };
-} // namespace __count_if
 
 inline namespace __cpo {
-inline constexpr auto count_if = __count_if::__fn{};
+inline constexpr auto count_if = __count_if{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_ends_with.h b/libcxx/include/__algorithm/ranges_ends_with.h
index 2afb74bff0f152..09fcd3173faf15 100644
--- a/libcxx/include/__algorithm/ranges_ends_with.h
+++ b/libcxx/include/__algorithm/ranges_ends_with.h
@@ -33,8 +33,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __ends_with {
-struct __fn {
+struct __ends_with {
   template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
   static _LIBCPP_HIDE_FROM_ABI constexpr bool __ends_with_fn_impl_bidirectional(
       _Iter1 __first1,
@@ -182,10 +181,9 @@ struct __fn {
     }
   }
 };
-} // namespace __ends_with
 
 inline namespace __cpo {
-inline constexpr auto ends_with = __ends_with::__fn{};
+inline constexpr auto ends_with = __ends_with{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_equal.h b/libcxx/include/__algorithm/ranges_equal.h
index 4cb1f7df1952e5..60be5f0a14a3ca 100644
--- a/libcxx/include/__algorithm/ranges_equal.h
+++ b/libcxx/include/__algorithm/ranges_equal.h
@@ -31,8 +31,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __equal {
-struct __fn {
+struct __equal {
   template <input_iterator _Iter1,
             sentinel_for<_Iter1> _Sent1,
             input_iterator _Iter2,
@@ -90,10 +89,9 @@ struct __fn {
     return false;
   }
 };
-} // namespace __equal
 
 inline namespace __cpo {
-inline constexpr auto equal = __equal::__fn{};
+inline constexpr auto equal = __equal{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_equal_range.h b/libcxx/include/__algorithm/ranges_equal_range.h
index 1ff8856ca03f1e..6b1313ed498388 100644
--- a/libcxx/include/__algorithm/ranges_equal_range.h
+++ b/libcxx/include/__algorithm/ranges_equal_range.h
@@ -35,9 +35,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __equal_range {
-
-struct __fn {
+struct __equal_range {
   template <forward_iterator _Iter,
             sentinel_for<_Iter> _Sent,
             class _Tp,
@@ -61,10 +59,8 @@ struct __fn {
   }
 };
 
-} // namespace __equal_range
-
 inline namespace __cpo {
-inline constexpr auto equal_range = __equal_range::__fn{};
+inline constexpr auto equal_range = __equal_range{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_fill.h b/libcxx/include/__algorithm/ranges_fill.h
index 88a892f5c27865..e9977fa0788864 100644
--- a/libcxx/include/__algorithm/ranges_fill.h
+++ b/libcxx/include/__algorithm/ranges_fill.h
@@ -25,8 +25,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __fill {
-struct __fn {
+struct __fill {
   template <class _Type, output_iterator<const _Type&> _Iter, sentinel_for<_Iter> _Sent>
   _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const {
     if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) {
@@ -43,10 +42,9 @@ struct __fn {
     return (*this)(ranges::begin(__range), ranges::end(__range), __value);
   }
 };
-} // namespace __fill
 
 inline namespace __cpo {
-inline constexpr auto fill = __fill::__fn{};
+inline constexpr auto fill = __fill{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_fill_n.h b/libcxx/include/__algorithm/ranges_fill_n.h
index dbd8ec27aef9f5..4f48d2ca22d359 100644
--- a/libcxx/include/__algorithm/ranges_fill_n.h
+++ b/libcxx/include/__algorithm/ranges_fill_n.h
@@ -22,8 +22,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __fill_n {
-struct __fn {
+struct __fill_n {
   template <class _Type, output_iterator<const _Type&> _Iter>
   _LIBCPP_HIDE_FROM_ABI constexpr _Iter
   operator()(_Iter __first, iter_difference_t<_Iter> __n, const _Type& __value) const {
@@ -34,10 +33,9 @@ struct __fn {
     return __first;
   }
 };
-} // namespace __fill_n
 
 inline namespace __cpo {
-inline constexpr auto fill_n = __fill_n::__fn{};
+inline constexpr auto fill_n = __fill_n{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_find.h b/libcxx/include/__algorithm/ranges_find.h
index de870e381184c6..7f71d8edae2294 100644
--- a/libcxx/include/__algorithm/ranges_find.h
+++ b/libcxx/include/__algorithm/ranges_find.h
@@ -33,8 +33,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __find {
-struct __fn {
+struct __find {
   template <class _Iter, class _Sent, class _Tp, class _Proj>
   _LIBCPP_HIDE_FROM_ABI static constexpr _Iter
   __find_unwrap(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
@@ -61,10 +60,9 @@ struct __fn {
     return __find_unwrap(ranges::begin(__r), ranges::end(__r), __value, __proj);
   }
 };
-} // namespace __find
 
 inline namespace __cpo {
-inline constexpr auto find = __find::__fn{};
+inline constexpr auto find = __find{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_find_end.h b/libcxx/include/__algorithm/ranges_find_end.h
index 2c57ad424bfdea..09f71117377be0 100644
--- a/libcxx/include/__algorithm/ranges_find_end.h
+++ b/libcxx/include/__algorithm/ranges_find_end.h
@@ -32,8 +32,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __find_end {
-struct __fn {
+struct __find_end {
   template <forward_iterator _Iter1,
             sentinel_for<_Iter1> _Sent1,
             forward_iterator _Iter2,
@@ -84,10 +83,9 @@ struct __fn {
     return {__ret.first, __ret.second};
   }
 };
-} // namespace __find_end
 
 inline namespace __cpo {
-inline constexpr auto find_end = __find_end::__fn{};
+inline constexpr auto find_end = __find_end{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_find_first_of.h b/libcxx/include/__algorithm/ranges_find_first_of.h
index ec6d52c63250b5..36bc02cab79b64 100644
--- a/libcxx/include/__algorithm/ranges_find_first_of.h
+++ b/libcxx/include/__algorithm/ranges_find_first_of.h
@@ -29,8 +29,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __find_first_of {
-struct __fn {
+struct __find_first_of {
   template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
   _LIBCPP_HIDE_FROM_ABI constexpr static _Iter1 __find_first_of_impl(
       _Iter1 __first1,
@@ -87,10 +86,9 @@ struct __fn {
         __proj2);
   }
 };
-} // namespace __find_first_of
 
 inline namespace __cpo {
-inline constexpr auto find_first_of = __find_first_of::__fn{};
+inline constexpr auto find_first_of = __find_first_of{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_find_if.h b/libcxx/include/__algorithm/ranges_find_if.h
index af54a5007ee259..bbefc50c4f486d 100644
--- a/libcxx/include/__algorithm/ranges_find_if.h
+++ b/libcxx/include/__algorithm/ranges_find_if.h
@@ -39,8 +39,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Ip __find_if_impl(_Ip __first, _Sp __last, _Pre
   return __first;
 }
 
-namespace __find_if {
-struct __fn {
+struct __find_if {
   template <input_iterator _Ip,
             sentinel_for<_Ip> _Sp,
             class _Proj = identity,
@@ -56,10 +55,9 @@ struct __fn {
     return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
   }
 };
-} // namespace __find_if
 
 inline namespace __cpo {
-inline constexpr auto find_if = __find_if::__fn{};
+inline constexpr auto find_if = __find_if{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_find_if_not.h b/libcxx/include/__algorithm/ranges_find_if_not.h
index a18bea43165e0d..9e8be60eee8f6d 100644
--- a/libcxx/include/__algorithm/ranges_find_if_not.h
+++ b/libcxx/include/__algorithm/ranges_find_if_not.h
@@ -31,8 +31,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace ranges {
-namespace __find_if_not {
-struct __fn {
+struct __find_if_not {
   template <input_iterator _Ip,
             sentinel_for<_Ip> _Sp,
             class _Proj = identity,
@@ -50,10 +49,9 @@ struct __fn {
     return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred2, __proj);
   }
 };
-} // namespace __find_if_not
 
 inline namespace __cpo {
-inline constexpr auto find_if_not = __find_if_not::__fn{};
+inline constexpr auto find_if_not = __find_if_not{};
 } // namespace __cpo
 } // namespace ranges
 
diff --git a/libcxx/include/__algorithm/ranges_for_each.h b/libcxx/include/__algorithm/ranges_for_each.h
index 7878ed26709fb6..a3bf7d4459cf1c 100644
--- a/libcxx/include/__algorithm/ranges_for_each.h
+++ b/libcxx/include/__algorithm/ranges_for_each.h
@@ -33,8 +33,7 @@ namespace ranges {
 template <class _Iter, class _Func>
 using for_each_result = in_fun_result<_Iter, _Func>;
 
-namespace __for_each {
-struct __fn {
+struct __for_each {
 private:
   template <class _Iter, class _Sent, class _Proj, class _Func>
   _LIBCPP_HIDE_FROM_ABI constexpr static for_each_result<_Iter, _Func>
@@ -62,10 +61,9 @@ struct __fn {
     return __for_each_impl(ranges::begin(__range), ranges::end(__range), __func, __proj);
   }
 };
-} // namespace __for_each
 
 inline namespace __cpo {
-inline constexpr auto for_each = __for_each::__fn{};
+inline constexpr auto for_eac...
[truncated]

@cjdb cjdb mentioned this pull request Jan 5, 2024
4 tasks
Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I have a vague recollection that there was a reason for putting them in a separate namespace, but if you say there wasn't then it's probably just my memory playing tricks on me.

@ldionne
Copy link
Member

ldionne commented Jan 16, 2024

I think the reason was simply to keep all niebloids and CPOs in sync and have a single way of implementing all of those. I think this is reasonable, but it would also be reasonable to keep them all in sync for consistency. Either way is fine with me, but I'd like us to close this one way or another to clear up the review queue :-)

@ldionne ldionne added the ranges Issues related to `<ranges>` label Mar 7, 2024
@var-const var-const self-assigned this Mar 8, 2024
I originally put implementation-detail function objects into individual
namespaces for `std::ranges` without a good reason for doing so. This
practice was continued after I left libc++, 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.
@ldionne ldionne merged commit d10dc5a into llvm:main Aug 1, 2024
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants