[libcxx-commits] [libcxx] [libc++] Optimize ranges::for_each for iterating over __trees (PR #164405)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 1 08:23:04 PST 2025


================
@@ -71,7 +73,13 @@ struct __for_each {
             indirectly_unary_invocable<projected<iterator_t<_Range>, _Proj>> _Func>
   _LIBCPP_HIDE_FROM_ABI constexpr for_each_result<borrowed_iterator_t<_Range>, _Func>
   operator()(_Range&& __range, _Func __func, _Proj __proj = {}) const {
-    return __for_each_impl(ranges::begin(__range), ranges::end(__range), __func, __proj);
+    using _SpecialAlg = __specialized_algorithm<_Algorithm::__for_each, remove_cvref_t<_Range>>;
----------------
ldionne wrote:

I think we should be using `__specialized_algorithm<_Algorithm::__for_each, __single_range<remove_cvref_t<_Range>>>` or something like that.

https://github.com/llvm/llvm-project/pull/164405


More information about the libcxx-commits mailing list