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

William Tran-Viet via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 21 10:18:22 PDT 2025


================
@@ -792,6 +829,18 @@ public:
     }
   }
 
+#    if _LIBCPP_STD_VER >= 26
+  // [optional.iterators], iterator support
+  _LIBCPP_HIDE_FROM_ABI constexpr iterator begin() noexcept { return iterator(std::addressof(this->__get())); }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr const_iterator begin() const noexcept {
+    return const_iterator(std::addressof(this->__get()));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr iterator end() noexcept { return begin() + this->has_value(); }
----------------
smallp-o-p wrote:

Yeah, I would've done this if not for the wording in the proposal, and I'm not entirely sure how much `libc++` prioritizes following the standard to the absolute letter: 

[Returns: begin() + has_value()](https://eel.is/c++draft/optional.iterators#5)

Implicit conversions are evil though, so it's probably better to have it be explicit as a code quality thing.  

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


More information about the libcxx-commits mailing list