[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:09 PDT 2026
================
@@ -114,6 +114,39 @@ struct SizedSentinelNotConstView : std::ranges::view_base {
bool operator==(const ForwardIter &lhs, int* rhs);
bool operator==(int* lhs, const ForwardIter &rhs);
+#if TEST_STD_VER >= 26
+struct ApproximatelySizedView : std::ranges::view_base {
+ int start_;
+ unsigned int reserve_hint_;
+
+ constexpr explicit ApproximatelySizedView(unsigned int hint, int start = 0) : start_(start), reserve_hint_(hint) {}
+ constexpr auto begin() const { return forward_iterator<int*>(globalBuff + start_); }
+ constexpr auto end() const { return forward_iterator<int*>(globalBuff + 8); }
+ constexpr unsigned int reserve_hint() const { return reserve_hint_; }
+};
+
+static_assert(std::ranges::view<ApproximatelySizedView>);
+static_assert(!std::ranges::sized_range<ApproximatelySizedView>);
+static_assert(std::ranges::approximately_sized_range<ApproximatelySizedView>);
+static_assert(std::ranges::approximately_sized_range<const ApproximatelySizedView>);
+
+struct ApproximatelySizedNotConstView : std::ranges::view_base {
+ int start_;
+ unsigned int reserve_hint_;
+
+ constexpr explicit ApproximatelySizedNotConstView(unsigned int hint, int start = 0)
+ : start_(start), reserve_hint_(hint) {}
+ constexpr auto begin() const { return forward_iterator<int*>(globalBuff + start_); }
+ constexpr auto end() const { return forward_iterator<int*>(globalBuff + 8); }
+ constexpr unsigned int reserve_hint() { return reserve_hint_; }
+};
+
+static_assert(std::ranges::view<ApproximatelySizedNotConstView>);
+static_assert(!std::ranges::sized_range<ApproximatelySizedNotConstView>);
+static_assert(std::ranges::approximately_sized_range<ApproximatelySizedNotConstView>);
+static_assert(!std::ranges::approximately_sized_range<const ApproximatelySizedNotConstView>);
+#endif
----------------
Zingam wrote:
Suggestion: Since these types aren't shared between tests, you can move them to the test that uses them. AFAIK That's the preferred practice to declare stuff closer to where it is used if possible.
Ditto for the other `types.h` (I am reviewing the PR in the order sections appear in the paper, so I won't repeat myself).
https://github.com/llvm/llvm-project/pull/206385
More information about the libcxx-commits
mailing list