[libcxx-commits] [libcxx] [libc++] Partially implement P2846R6: `reserve_hint` (PR #206385)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 29 04:41:25 PDT 2026
================
@@ -131,6 +131,59 @@ inline constexpr auto ssize = __ssize::__fn{};
} // namespace __cpo
} // namespace ranges
+# if _LIBCPP_STD_VER >= 26
+
+// [range.prim.size.hint]
+
+namespace ranges {
+namespace __reserve_hint {
+void reserve_hint() = delete;
+
+template <typename _Tp>
+concept __std_size = requires(_Tp&& __t) { ranges::size(__t); };
+
+template <typename _Tp>
+concept __member_reserve_hint = !__std_size<_Tp> && requires(_Tp&& __t) {
+ { auto(__t.reserve_hint()) } -> __integer_like;
+};
+
+template <typename _Tp>
+concept __unqualified_reserve_hint =
+ !__std_size<_Tp> && !__member_reserve_hint<_Tp> && __class_or_enum<remove_cvref_t<_Tp>> && requires(_Tp&& __t) {
+ { auto(reserve_hint(__t)) } -> __integer_like;
+ };
+
+struct __fn {
+ // `[range.prim.size.hint]`: `std::size(t)` is a valid expression
----------------
frederick-vs-ja wrote:
The standard doesn't say `std::size` for these cases. Also, `__std_size` should probably be renamed.
https://github.com/llvm/llvm-project/pull/206385
More information about the libcxx-commits
mailing list