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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 5 08:57:52 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>>>;
----------------
ldionne wrote:

I actually think we can get rid of `__wrap_iter` entirely here. The purpose of `__wrap_iter` is primarily to prevent people from relying on the fact that an iterator is actually a pointer, but in this case we're already wrapping the underlying pointers, so I think we're good. We could remove the `__wrap_iter` include too.

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


More information about the libcxx-commits mailing list