int main() {
vector<int> nums{-15,19};
auto d = nums
|std::views::chunk_by(std::ranges::less{})
|std::views::transform(std::ranges::distance)
|std::views::adjacent_transform<2>([](auto a, auto b) {
return std::max(std::max(a, b) / 2, std::min(a, b));
});
cout << ranges::max(d) << endl; // so there is 1 output
for (auto&& x :d) {
cout << x << ' ';//but there is nothing, wtf? I think there is must a number like 1
}
这段代码是进行一些计算,我希望它用上面的一些逻辑来计算相邻的数字
return std::max(std::max(a, b) / 2, std::min(a, b));
所以当向量size()为2时,我认为adjacent_transform
会产生未定义的行为?因为它只有一个数字,但是 cppreference 说它会返回 0,但是...但是 ranges::max
返回 1,所以有太多的话要说...只是一切都是一团糟,f**k cpp .
所以我想我想出了一些办法。 cppref 很清楚,cppref 说当 S < N the adjacent_transform will return a empty view. so output nothing is very right, so the question is why ranges::max about this empty view 's result is 1? i think this is the matter now.