[libcxx-commits] [libcxx] [libc++] P3168R2 Give std::optional Range Support (PR #146491)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 1 04:19:35 PDT 2025
================
@@ -578,6 +600,71 @@ struct __is_std_optional : false_type {};
template <class _Tp>
struct __is_std_optional<optional<_Tp>> : true_type {};
+# if _LIBCPP_STD_VER >= 26
+
+template <class _T>
+constexpr bool ranges::enable_view<optional<_T>> = true;
+
+template <class _T>
+constexpr auto format_kind<optional<_T>> = range_format::disabled;
+
+template <typename _Tp>
+class __optional_iterator {
+public:
+ using value_type = _Tp;
+ using difference_type = std::ptrdiff_t;
+ using pointer = _Tp*;
+ using reference = _Tp&;
+ using iterator_category = std::forward_iterator_tag;
----------------
frederick-vs-ja wrote:
This is wrong. This iterator type must be a contiguous access iterator.
```suggestion
using iterator_category = random_access_iterator_tag;
using iterator_concept = contiguous_iterator_tag;
```
https://github.com/llvm/llvm-project/pull/146491
More information about the libcxx-commits
mailing list