Let's say I've got a string such as string values = "hello 2 88.9 true"
which holds several values of different types. I have several variables which were declared with the appropriate types (here a string, an int, a float and a bool). What I basically want to do is this :
field0 = getValue(0,values);
field1 = getValue(1,values);
... etc
So what I want is a getValue
whose return type matches the type of the corresponding field. Is this possible with simply templates ? I feel like you cannot just specify the return type you want to use without having the template type in the parameters of the template function.
The body of the function itself is probably going to use boost's lexical_cast and a stringstream but if you have a better solution, I'm up for that as well !
I'm new to templates so I would very much appreciate an explanation...