I have a function that I'd like to generalize. Simply put, I have a std::string s that I process with a parser generating a std::vector<std::string> (it's a list as in "1, 2, 3"), and the function should return a std::vector<T>, with T restricted to double or int.
The vector should contain the transformed values.
I am stuck with the last parameter of std::transform, as it should switch between std::stod and std::stoi.
Any hints?
template <class T>
auto get_vector(std::string s) -> std::vector<T>
{
std::vector<T> v;
auto tmp = split(s);
std::transform(tmp.begin(), tmp.end(), std::back_inserter(v), ??);
return v;
}
Aucun commentaire:
Enregistrer un commentaire