[libcxx-commits] [libcxx] [libc++][NFC] Simplify `optional<T>` and `optional<T&>` a bit (PR #203665)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jun 13 02:57:19 PDT 2026


frederick-vs-ja wrote:

> I think it's because `__optional_iterator_base<_Tp&>` is only experimental, and it would default to the empty `__optional_iterator_base<_Tp>` in non-experimental which still inherits from the other base classes, of which I removed the checks that made it trivial.

Then I think we can always expose `__optional_iterator_base<_Tp&>` in C++26, and refactor it like the following.
```C++
#if _LIBCPP_STD_VER >= 26
template <class _Tp>
struct __optional_iterator_base<_Tp&>
    : __optional_storage_base<_Tp&> {
  using __optional_storage_base<_Tp&>::__optional_storage_base;
};

#if _LIBCPP_HAS_EXPERIMENTAL_OPTIONAL_ITERATOR
template <class _Tp>
  requires (is_object_v<_Tp> && !__is_unbounded_array_v<_Tp>)
struct __optional_iterator_base<_Tp&>
    : __optional_storage_base<_Tp&> { /* ... */ };
#endif // _LIBCPP_HAS_EXPERIMENTAL_OPTIONAL_ITERATOR
#endif // _LIBCPP_STD_VER >= 26
```

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


More information about the libcxx-commits mailing list