我正在尝试使用范围比较 2 个数组并想打印它。
#include <algorithm>
#include <iostream>
#include <iterator>
#include <array>
#include <ranges>
int main()
{
std::array<int, 9> test{0, 2, 3, 8, 0, 5, 4, 0, 1};
std::array<int, 9> ref{1, 2, 3, 4, 5, 6, 7, 8, 9};
//auto found = std::views::take_while([ ref, test ](auto *it) -> auto { it = std::ranges::find_first_of(ref, test); return it; });
auto found1 = std::views::take_while([ref, test]() { return std::ranges::find_first_of(ref, test); });
int *i{0};
while (*i != std::ranges::end(found1)){
std::cout << i << " ";
i++;
}
}
但未能编译错误我不明白
$ g++ main.cpp -std=c++20 -o main
main.cpp: In function ‘int main()’:
main.cpp:16:39: error: no match for call to ‘(const std::ranges::__cust_access::_End) (std::ranges::views::__adaptor::_RangeAdaptorClosure<std::ranges::views::__adaptor::_RangeAdaptor<_Callable>::operator()<{main()::<lambda()>}>::<lambda(_Range&&)> >&)’
16 | while (*i != std::ranges::end(found1)){
| ^
有没有办法打印 found1 ?