[libcxx-commits] [libcxx] [libc++] Collapse `optional<T&>` inheritance hierarchy (PR #215286)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 12 10:03:45 PDT 2026


================
@@ -102,75 +109,28 @@ struct __optional_ref_base {
     if (__opt.has_value())
       __construct(std::forward<_That>(__opt).__get());
   }
-};
 
-template <class _Tp>
-struct __optional_ref_iterator_base : __optional_ref_base<_Tp&> {
-  using __optional_ref_base<_Tp&>::__optional_ref_base;
-};
-
-#  if _LIBCPP_HAS_EXPERIMENTAL_OPTIONAL_ITERATOR
-
-template <class _Tp>
-  requires(is_object_v<_Tp> && !__is_unbounded_array_v<_Tp>)
-struct __optional_ref_iterator_base<_Tp&> : __optional_ref_base<_Tp&> {
-private:
-  using __pointer _LIBCPP_NODEBUG = add_pointer_t<_Tp>;
+  static constexpr bool __has_iterator_ = requires { typename __optional_ref_iterator_base<_Tp&>::iterator; };
----------------
frederick-vs-ja wrote:

I'd like to merge this PR now. Maybe it's preferred to extract this concept in a follow-up PR.

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


More information about the libcxx-commits mailing list