Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LWG-3984 ranges::to's recursion branch may be ill-formed #4543

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -10372,7 +10372,7 @@ namespace ranges {
const auto _Xform = [](auto&& _Elem) _STATIC_CALL_OPERATOR {
return _RANGES to<range_value_t<_Container>>(_STD forward<decltype(_Elem)>(_Elem));
};
return _RANGES to<_Container>(views::transform(_Range, _Xform), _STD forward<_Types>(_Args)...);
return _RANGES to<_Container>(views::transform(ref_view{_Range}, _Xform), _STD forward<_Types>(_Args)...);
} else {
static_assert(_Always_false<_Container>, "the program is ill-formed per N4950 [range.utility.conv.to]/2.3");
}
Expand Down
11 changes: 11 additions & 0 deletions tests/std/tests/P1206R7_ranges_to_sequence/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ struct sequence_instantiator {
template <template <class...> class C, class T, class... Args>
using deduce_container = deduce_container_impl<C>::template apply<T, Args...>;

template <class>
static constexpr bool is_basic_string = false;
template <class CharT, class Traits, class Alloc>
static constexpr bool is_basic_string<std::basic_string<CharT, Traits, Alloc>> = true;

static constexpr auto meow = "meow"sv;

template <template <class...> class C>
Expand Down Expand Up @@ -96,6 +101,12 @@ struct sequence_instantiator {
std::same_as<C<char>> auto c7 = c | ranges::to<C>();
assert(c7 == c);
}
if constexpr (!is_basic_string<C<char>>) { // LWG-3984 "ranges::to's recursion branch may be ill-formed"
auto owning = std::views::all(C<C<char>>{c});
std::same_as<C<C<int>>> auto c8 = owning | ranges::to<C<C<int>>>();
assert(
ranges::equal(c8, C<C<char>>{c}, [](const auto& r1, const auto& r2) { return ranges::equal(r1, r2); }));
}

return true;
}
Expand Down