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