So what I am trying to do is write a generic function that takes in a string a splits it into a typed vector. Here is my code, and the issue is that it can't resolve the stod function type to the generic function wrapper I specified.
#include <string>
#include <sstream>
#include <vector>
#include <iostream>
#include <functional>
using std::vector;
using std::string;
using std::function;
using std::stringstream;
int main(int argc, const char * argv[]) {
SplitStringToTypedVector("1.23 3.45 5.21", ' ', static_cast<double (*)(const string&, size_t*)>(&std::stod));
system("pause");
return 0;
}
template <typename T>
vector<T> SplitStringToTypedVector(const string &s, char delim, function<T (*)(const string&, size_t*)> conversionFunc) {
vector<T> elements;
stringstream stream;
string element;
while (getline(stream, element, delim)) {
elements.push_back(conversionFunc(element));
}
return elements;
}