[libc++] Backport segmented iterator optimization for std::for_each to C++11 (#134960)
Previously, the segmented iterator optimization for `std::for_each` was restricted to C++23 and later due to its dependency on `__movable_box`, which is not available in earlier standards. This patch eliminates that restriction, enabling consistent optimizations starting from C++11.
By backporting this enhancement, we improve performance across older standards and create opportunities to extend similar optimizations to other algorithms by forwarding their calls to `std::for_each`.
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index bf67d33..64e9fa6 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -2061,6 +2061,7 @@
# include <cstring>
# include <iterator>
# include <memory>
+# include <optional>
# include <stdexcept>
# include <type_traits>
# include <utility>