[libcxx-commits] [libcxx] [libc++] Implement a type-safe iterator for optional (PR #154239)

William Tran-Viet via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 5 17:24:25 PST 2025


================
@@ -688,52 +688,53 @@ private:
   using __pointer _LIBCPP_NODEBUG       = add_pointer_t<remove_reference_t<_Tp>>;
   using __const_pointer _LIBCPP_NODEBUG = add_pointer_t<const remove_reference_t<_Tp>>;
 
-public:
 #    if _LIBCPP_STD_VER >= 26
+  template <typename _Underlying>
+  using __iter _LIBCPP_NODEBUG = __upper_bounded_iterator<_Underlying, __optional_iterator, 1>;
+
+public:
 #      ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_OPTIONAL
-  using iterator       = __bounded_iter<__wrap_iter<__pointer>>;
-  using const_iterator = __bounded_iter<__wrap_iter<__const_pointer>>;
+  using iterator       = __iter<__bounded_iter<__wrap_iter<__pointer>>>;
----------------
smallp-o-p wrote:

I am fairly certain we'd have to re-implement most of `wrap_iter.h` in `__upper_bounded_iterator` (now `__capacity_aware_iterator`), and it might also constrain it to `contiguous_iterator` only due to `std::optional`'s requirement for it. I'm not sure if that's what you were intending. 

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


More information about the libcxx-commits mailing list