libstdc++: Implement LWG 3563 changes to keys_view and values_view

This LWG issue corrects the definition of these alias templates to make
them suitable for alias CTAD.

libstdc++-v3/ChangeLog:

	* include/std/ranges (keys_view): Adjust as per LWG 3563.
	(values_view): Likewise.
	* testsuite/std/ranges/adaptors/elements.cc (test08): New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
This commit is contained in:
Patrick Palka 2024-11-14 13:27:41 -05:00
parent 4a3a0be34f
commit 361050589b
2 changed files with 18 additions and 2 deletions

View File

@ -4551,11 +4551,13 @@ namespace views::__adaptor
inline constexpr bool enable_borrowed_range<elements_view<_Tp, _Nm>>
= enable_borrowed_range<_Tp>;
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 3563. keys_view example is broken
template<typename _Range>
using keys_view = elements_view<views::all_t<_Range>, 0>;
using keys_view = elements_view<_Range, 0>;
template<typename _Range>
using values_view = elements_view<views::all_t<_Range>, 1>;
using values_view = elements_view<_Range, 1>;
namespace views
{

View File

@ -148,6 +148,19 @@ test07()
b == e;
}
void
test08()
{
// LWG 3563 - keys_view example is broken
std::pair<int, int> x[] = {{1,2},{3,4}};
auto v = ranges::keys_view{views::all(x)};
auto w = ranges::values_view{views::all(x)};
using ty1 = decltype(v);
using ty1 = ranges::elements_view<views::all_t<decltype((x))>, 0>;
using ty2 = decltype(w);
using ty2 = ranges::elements_view<views::all_t<decltype((x))>, 1>;
}
int
main()
{
@ -158,4 +171,5 @@ main()
test05();
test06();
test07();
test08();
}