ranges/adjacent: use more cvref_t

This fixes some errors calling the range closure with stack variables.
This commit is contained in:
Danny Robson 2024-11-11 11:26:44 +10:00
parent 8eeb35cf36
commit e3ab977ffa
2 changed files with 6 additions and 4 deletions

View File

@ -158,7 +158,7 @@ namespace cruft::ranges {
decltype (auto) decltype (auto)
operator () (V &&v) const operator () (V &&v) const
{ {
return adjacent_view<V, N> ( return adjacent_view<std::remove_cvref_t<V>, N> (
std::forward<V> (v) std::forward<V> (v)
); );
} }

View File

@ -6,8 +6,8 @@
int main() int main()
{ {
static int constexpr INPUT[] = { 1, 1, 2, 3, 5, 8 }; static int const constexpr INPUT[] = { 1, 1, 2, 3, 5, 8 };
static int constexpr EXPECTED[][2] = { static int const constexpr EXPECTED[][2] = {
{ 1, 1 }, { 1, 1 },
{ 1, 2 }, { 1, 2 },
{ 2, 3 }, { 2, 3 },
@ -17,8 +17,10 @@ int main()
cruft::TAP::logger tap; cruft::TAP::logger tap;
// Use a temporary in an attempt to trigger cvref related type errors when calling the range closure.
std::span<int const> input_span (INPUT);
const bool same = std::ranges::equal ( const bool same = std::ranges::equal (
std::views::all (INPUT) | cruft::ranges::pairwise, input_span | cruft::ranges::pairwise,
EXPECTED, EXPECTED,
[] (auto const &a, auto const &b) { return std::ranges::equal (a, b); } [] (auto const &a, auto const &b) { return std::ranges::equal (a, b); }
); );