[libcxx-commits] [libcxx] [libc++] Partially implement P2846R6: `reserve_hint` (PR #206385)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 13 02:07:08 PDT 2026


================
@@ -139,6 +140,30 @@ class adjacent_view : public view_interface<adjacent_view<_View, _Np>> {
     __sz -= std::min<_CT>(__sz, _Np - 1);
     return static_cast<_ST>(__sz);
   }
+
+#  if _LIBCPP_STD_VER >= 26
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto reserve_hint()
+    requires approximately_sized_range<_View>
+  {
+    using _ST = decltype(ranges::reserve_hint(__base_));
+    using _CT = common_type_t<_ST, size_t>;
+    auto __sz = static_cast<_CT>(ranges::reserve_hint(__base_));
+    __sz -= std::min<_CT>(__sz, _Np - 1);
+    return static_cast<_ST>(__sz);
----------------
frederick-vs-ja wrote:

We should use `std::__to_unsigned_like`.

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


More information about the libcxx-commits mailing list