PR libstdc++/122425

libstdc++-v3/ChangeLog:

        * include/std/optional
        (ranges::enable_borrowed_range<optional<_Tp&>>): Define.
        * testsuite/20_util/optional/range.cc: Update tests.
---
 libstdc++-v3/include/std/optional                | 6 ++++++
 libstdc++-v3/testsuite/20_util/optional/range.cc | 6 +++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index fad5f57a94c..5407fc74a41 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -2178,6 +2178,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline constexpr bool
       ranges::enable_view<optional<_Tp>> = true;
 
+#if __cpp_lib_optional >= 202506L // C++26
+  template<typename _Tp>
+    constexpr bool
+    ranges::enable_borrowed_range<optional<_Tp&>> = true;
+#endif
+ 
   template<typename _Tp>
     inline constexpr range_format
       format_kind<optional<_Tp>> = range_format::disabled;
diff --git a/libstdc++-v3/testsuite/20_util/optional/range.cc 
b/libstdc++-v3/testsuite/20_util/optional/range.cc
index 1cb3eb6ceff..981969cb614 100644
--- a/libstdc++-v3/testsuite/20_util/optional/range.cc
+++ b/libstdc++-v3/testsuite/20_util/optional/range.cc
@@ -19,12 +19,16 @@ test_range_concepts()
   static_assert(std::ranges::contiguous_range<O>);
   static_assert(std::ranges::sized_range<O>);
   static_assert(std::ranges::common_range<O>);
-  static_assert(!std::ranges::borrowed_range<O>);
+
+  // an optional<T&> is borrowed range
+  constexpr bool is_ref_opt = std::is_reference_v<T>;
+  static_assert(std::ranges::borrowed_range<O> == is_ref_opt);
 
   // an optional<const T> is not assignable, and therefore does not satisfy 
ranges::view
   constexpr bool is_const_opt = std::is_const_v<T>;
   static_assert(std::ranges::view<O> == !is_const_opt);
   static_assert(std::ranges::viewable_range<O> == !is_const_opt);
+
 }
 
 template<typename O>
-- 
2.51.0

Reply via email to