[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:30:03 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 = __capacity_aware_iterator<_Underlying, optional<_Tp>, 1>;
+
+public:
# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_OPTIONAL
using iterator = __bounded_iter<__wrap_iter<__pointer>>;
----------------
smallp-o-p wrote:
I'm not sure whether it's worth it to wrap `__bounded_iter`, other than for type safety in the ABI break mode. The check provided by `__capacity_aware_iterator` would become useless overhead, although may just get optimized out? Not sure.
https://github.com/llvm/llvm-project/pull/154239
More information about the libcxx-commits
mailing list