@@ -205,6 +205,7 @@ namespace std {
205
205
# include < __functional/invoke.h>
206
206
# include < __functional/unary_function.h>
207
207
# include < __fwd/functional.h>
208
+ # include < __iterator/bounded_iter.h>
208
209
# include < __iterator/wrap_iter.h>
209
210
# include < __memory/addressof.h>
210
211
# include < __memory/construct_at.h>
@@ -622,8 +623,13 @@ class _LIBCPP_DECLSPEC_EMPTY_BASES optional
622
623
public:
623
624
using value_type = _Tp;
624
625
# if _LIBCPP_STD_VER >= 26
626
+ # ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_OPTIONAL
627
+ using iterator = __bounded_iter<__wrap_iter<pointer>>;
628
+ using const_iterator = __bounded_iter<__wrap_iter<const_pointer>>;
629
+ # else
625
630
using iterator = __wrap_iter<pointer>;
626
631
using const_iterator = __wrap_iter<const_pointer>;
632
+ # endif
627
633
# endif
628
634
629
635
using __trivially_relocatable _LIBCPP_NODEBUG =
@@ -831,10 +837,26 @@ public:
831
837
832
838
# if _LIBCPP_STD_VER >= 26
833
839
// [optional.iterators], iterator support
834
- _LIBCPP_HIDE_FROM_ABI constexpr iterator begin () noexcept { return iterator (std::addressof (this ->__get ())); }
840
+ _LIBCPP_HIDE_FROM_ABI constexpr iterator begin () noexcept {
841
+ # ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_OPTIONAL
842
+ return std::__make_bounded_iter (
843
+ std::__wrap_iter<pointer>(std::addressof (this ->__get ())),
844
+ std::__wrap_iter<pointer>(std::addressof (this ->__get ())),
845
+ std::__wrap_iter<pointer>(std::addressof (this ->__get ()) + (this ->has_value ()) ? 1 : 0 ));
846
+ # else
847
+ return iterator (std::addressof (this ->__get ()));
848
+ # endif
849
+ }
835
850
836
851
_LIBCPP_HIDE_FROM_ABI constexpr const_iterator begin () const noexcept {
852
+ # ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_OPTIONAL
853
+ return std::__make_bounded_iter (
854
+ std::__wrap_iter<const_pointer>(std::addressof (this ->__get ())),
855
+ std::__wrap_iter<const_pointer>(std::addressof (this ->__get ())),
856
+ std::__wrap_iter<const_pointer>(std::addressof (this ->__get ()) + (this ->has_value ()) ? 1 : 0 ));
857
+ # else
837
858
return const_iterator (std::addressof (this ->__get ()));
859
+ # endif
838
860
}
839
861
840
862
_LIBCPP_HIDE_FROM_ABI constexpr iterator end () noexcept { return begin () + (this ->has_value () ? 1 : 0 ); }
0 commit comments