From e3ab977ffaee274de8de6f77e8149988089bdbad Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 11 Nov 2024 11:26:44 +1000 Subject: [PATCH] ranges/adjacent: use more cvref_t This fixes some errors calling the range closure with stack variables. --- cruft/util/ranges/adjacent.hpp | 2 +- test/ranges/adjacent.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cruft/util/ranges/adjacent.hpp b/cruft/util/ranges/adjacent.hpp index 5848940a..16934080 100644 --- a/cruft/util/ranges/adjacent.hpp +++ b/cruft/util/ranges/adjacent.hpp @@ -158,7 +158,7 @@ namespace cruft::ranges { decltype (auto) operator () (V &&v) const { - return adjacent_view ( + return adjacent_view, N> ( std::forward (v) ); } diff --git a/test/ranges/adjacent.cpp b/test/ranges/adjacent.cpp index 97cae2d6..15b95815 100644 --- a/test/ranges/adjacent.cpp +++ b/test/ranges/adjacent.cpp @@ -6,8 +6,8 @@ int main() { - static int constexpr INPUT[] = { 1, 1, 2, 3, 5, 8 }; - static int constexpr EXPECTED[][2] = { + static int const constexpr INPUT[] = { 1, 1, 2, 3, 5, 8 }; + static int const constexpr EXPECTED[][2] = { { 1, 1 }, { 1, 2 }, { 2, 3 }, @@ -17,8 +17,10 @@ int main() cruft::TAP::logger tap; + // Use a temporary in an attempt to trigger cvref related type errors when calling the range closure. + std::span input_span (INPUT); const bool same = std::ranges::equal ( - std::views::all (INPUT) | cruft::ranges::pairwise, + input_span | cruft::ranges::pairwise, EXPECTED, [] (auto const &a, auto const &b) { return std::ranges::equal (a, b); } );