diff mbox series

libstdc++: Add ranges::range_common_reference_t for C++20 (LWG 3860)

Message ID 20240612203233.879427-1-jwakely@redhat.com
State New
Headers show
Series libstdc++: Add ranges::range_common_reference_t for C++20 (LWG 3860) | expand

Commit Message

Jonathan Wakely June 12, 2024, 8:32 p.m. UTC
Jason noticed this was missing.

Tested x86_64-linux.

-- >8 --

LWG 3860 added this alias template. Both libc++ and MSVC treat this as a
DR for C++20, so this change does so too.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (range_common_reference_t): New
	alias template, as per LWG 3860.
	* testsuite/std/ranges/range.cc: Check it.
---
 libstdc++-v3/include/bits/ranges_base.h    | 6 ++++++
 libstdc++-v3/testsuite/std/ranges/range.cc | 6 ++++++
 2 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h
index 23c0b56ff22..63eb552b48b 100644
--- a/libstdc++-v3/include/bits/ranges_base.h
+++ b/libstdc++-v3/include/bits/ranges_base.h
@@ -537,6 +537,12 @@  namespace ranges
     using range_rvalue_reference_t
       = iter_rvalue_reference_t<iterator_t<_Range>>;
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3860. range_common_reference_t is missing
+  template<range _Range>
+    using range_common_reference_t
+      = iter_common_reference_t<iterator_t<_Range>>;
+
   /// [range.sized] The sized_range concept.
   template<typename _Tp>
     concept sized_range = range<_Tp>
diff --git a/libstdc++-v3/testsuite/std/ranges/range.cc b/libstdc++-v3/testsuite/std/ranges/range.cc
index 18435659137..760f6ffacfd 100644
--- a/libstdc++-v3/testsuite/std/ranges/range.cc
+++ b/libstdc++-v3/testsuite/std/ranges/range.cc
@@ -83,3 +83,9 @@  static_assert( same_as<std::ranges::range_rvalue_reference_t<I>,
 		       char&&> );
 static_assert( same_as<std::ranges::range_rvalue_reference_t<O>,
 		      WritableObject<char>> );
+
+// LWG 3860. range_common_reference_t is missing
+static_assert( same_as<std::ranges::range_common_reference_t<C>,
+		       char&> );
+static_assert( same_as<std::ranges::range_common_reference_t<I>,
+		       char&> );