3
如何使用std::transform
和std::foreach
来实现这个? (无C++ 11)使用std :: transform指数向量
std::vector<double> exp_c(const std::vector<double>& x) {
const int n = x.size();
std::vector<double> y(n);
for (int i = 0; i < n; i++) {
y[i] = std::exp(x[i]);
}
return y;
}
感谢。
相关:http://stackoverflow.com/questions/356950/c-functors-and-their-uses – NathanOliver