[libcxx-commits] [libcxx] [libc++] Implement P3168R2: Give optional range support (PR #149441)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 24 22:51:08 PDT 2025


================
@@ -586,8 +614,17 @@ class _LIBCPP_DECLSPEC_EMPTY_BASES optional
       private __optional_sfinae_assign_base_t<_Tp> {
   using __base _LIBCPP_NODEBUG = __optional_move_assign_base<_Tp>;
 
+#    if _LIBCPP_STD_VER >= 26
+  using pointer       = std::add_pointer_t<std::remove_cvref_t<_Tp>>;
+  using const_pointer = std::add_pointer_t<const std::remove_cvref_t<_Tp>>;
+#    endif
+
 public:
   using value_type = _Tp;
+#    if _LIBCPP_STD_VER >= 26
+  using iterator       = __wrap_iter<pointer>;
----------------
frederick-vs-ja wrote:

Considering `optional<T(&)[]>` (note the missing bound) or `optional<T(&)(Args)>`, I wonder whether they should have `iterator`. Certainly, such an `iterator` can't be a contiguous iterator (and not even a real iterator in the case of `optional<T(&)(Args)>`), and our wrappers don't seem to work with them. If we decide they should have `iterator`, we probably need to introduce `optional`-specific iterators. @philnik777 @ldionne 

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


More information about the libcxx-commits mailing list