[libcxx-commits] [libcxx] [libc++] Partially implement P2846R6: `reserve_hint` (PR #206385)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 7 03:55:08 PDT 2026
================
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<V>;
+// constexpr auto reserve_hint() const
+// requires approximately_sized_range<const V>;
+
+#include <cassert>
+#include <ranges>
+
+#include "test_iterators.h"
+#include "types.h"
+
+template <class View>
+concept ReserveHintEnabled = requires(View v) { v.reserve_hint(); };
+
+constexpr bool test() {
+ int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+ {
+ static_assert(ReserveHintEnabled<std::ranges::common_view<ApproximatelySizedView>&>);
+ static_assert(ReserveHintEnabled<std::ranges::common_view<ApproximatelySizedView> const&>);
+ static_assert(!ReserveHintEnabled<std::ranges::common_view<CopyableView>&>);
+ static_assert(!ReserveHintEnabled<std::ranges::common_view<CopyableView> const&>);
+ static_assert(ReserveHintEnabled<std::ranges::common_view<NonConstApproximatelySizedView>&>);
+ static_assert(!ReserveHintEnabled<std::ranges::common_view<NonConstApproximatelySizedView> const&>);
+ }
----------------
Zingam wrote:
These SFINAE style test cases will be called twice for no good reason, right? Commonly we place them outside of the test functions first. They don't need to be in the body of the test function.
https://github.com/llvm/llvm-project/pull/206385
More information about the libcxx-commits
mailing list