libcruft-util/test/ranges/adjacent.cpp
Danny Robson e3ab977ffa ranges/adjacent: use more cvref_t
This fixes some errors calling the range closure with stack variables.
2024-11-11 11:26:44 +10:00

31 lines
775 B
C++

#include <cruft/util/ranges/adjacent.hpp>
#include <cruft/util/tap.hpp>
#include <algorithm>
int main()
{
static int const constexpr INPUT[] = { 1, 1, 2, 3, 5, 8 };
static int const constexpr EXPECTED[][2] = {
{ 1, 1 },
{ 1, 2 },
{ 2, 3 },
{ 3, 5 },
{ 5, 8 },
};
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 (
input_span | cruft::ranges::pairwise,
EXPECTED,
[] (auto const &a, auto const &b) { return std::ranges::equal (a, b); }
);
tap.expect (same, "ranges::pairwise fibonacci");
return tap.status ();
}