[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
Mon Dec 29 22:24:08 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:

Not requested for this PR. I think we should fix this later.

Per [[optional.optional.ref.general]](https://eel.is/c++draft/optional.optional.ref.general), `optional<T&>` shoudn't have `const_iterator`. We seemed to overlook this previously.

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


More information about the libcxx-commits mailing list