为什么我使用 transform_reduce 会产生编译错误?

问题描述 投票:0回答:0

当我尝试编译时

double f(Eigen::Vector<double, 2> const& h) { /* ... */ }

std::vector<Eigen::Vector<double, 2>> x;
Eigen::Vector<double, 2> y;

std::transform_reduce(x.begin(), x.end(), 0.,
    [&](auto const& x) { return f(Eigen::Vector<double, 2>{ y - x }); }, std::plus<>{});

编译器报错:

binary '-': 'Eigen::Matrix' 没有定义这个 运算符或转换为预定义可接受的类型 运营商。

编译时

Eigen::Vector<double, 2> x, y;
f(Eigen::Vector<double, 2>{ y - x });

相反,一切正常。这里出了什么问题?

stl c++20 eigen visual-studio-2022
© www.soinside.com 2019 - 2024. All rights reserved.