[libcxx-commits] [libcxx] [libc++] Partially implement P2846R6: `reserve_hint` (PR #206385)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Sep 27 00:42:01 PDT 2026
================
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// constexpr auto reserve_hint()
+// requires approximately_sized_range<R>
+// constexpr auto reserve_hint() const
+// requires approximately_sized_range<const R>
+
+#include <array>
+#include <cassert>
+#include <concepts>
+#include <ranges>
+#include <utility>
+
+#include "test_iterators.h"
+
+int globalBuff[8];
+
+template <class T>
+concept HasReserveHint = requires(T t) { t.reserve_hint(); };
----------------
inquisitivecrystal wrote:
I believe I've now done this. `HasReserveHint` is defined once in `libcxx/test/support/test_range.h`. The one exceptional case is `ReserveHintIsInvocable` in `range.ref.view/range.ref.view.pass.cpp`. But that's slightly different, defined like this:
```c++
template <class R>
concept ReserveHintIsInvocable = requires(std::ranges::ref_view<R> view) { view.reserve_hint(); };
```
This pattern matches other examples in the same file such as `EmpyIsInvocable` and SizeIsInvocable`. I'd strongly prefer to keep to the same pattern for intra-file consistency.
https://github.com/llvm/llvm-project/pull/206385
More information about the libcxx-commits
mailing list