[libcxx-commits] [libcxx] [libc++] Resolve LWG4308: `std::optional<T&>::iterator` can't be a contiguous iterator for some T (PR #173948)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 30 00:32:19 PST 2025


================
@@ -19,6 +19,12 @@
 #include <type_traits>
 #include <utility>
 
+template <typename T>
+concept has_iterator = requires {
+  typename T::iterator;
+  typename T::const_iterator;
+};
+
----------------
frederick-vs-ja wrote:

Yeah. Now I think we should test that
- `optional<Object>` has both `iterator` and `const_iterator`,
- "usual" `optional<T&>` has `iterator` but not `const_iterator` (fix needed, but can be done later), and
- "unusual" `optional<T&>` (impacted by LWG4308) has neither `iterator` nor `const_iterator`.

So IMO, it would make more sense to have separated `has_iterator` and `has_const_iterator` and test these separately.

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


More information about the libcxx-commits mailing list