#include <algorithm>
#include <iostream>
#include <ranges>
#include <vector>
struct S {
int n=0;
};
int main() {
std::vector<S> v= { {1}, {2}, {3}, {4}, {5}, {6}, {7} };
const int excluder = 7;
auto it_max = std::ranges::minmax_element(
v | std::views::filter([=](const auto& s) { return s.n != excluder ; }),
std::less<int>(), &S::n
).max;
std::cout << it_max->n;
}
编译错误:
:20:24: error: member reference type 'std::ranges::dangling' is not a pointer; did you mean to use '.'?
20 | std::cout << it_max->n;
| ~~~~~~^~
| .
:20:26: error: no member named 'n' in 'std::ranges::dangling'
20 | std::cout << it_max->n;
| ~~~~~~ ^