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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 21 09:44:28 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(); }
----------------
ldionne wrote:

```suggestion
  _LIBCPP_HIDE_FROM_ABI constexpr iterator end() noexcept { return begin() + (this->has_value() ? 1 : 0); }
```

Both are equivalent, but using a `bool` as an integer is usually frowned upon. This is a suggestion, not a hard request.

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


More information about the libcxx-commits mailing list