while passing serialized information over network I often have to deal with strings like this:
params can represent strings or ints or any other POD type.
I want to write a function which shall do the following:
the source string
the definition of the _DIVIDETOKEN_ (which is a string, too) and
the types I want the substrings to be converted to. If any conversion fails, an
exception shall be thrown
So question number one would be, how can I pass the wanted types to the function?
Default would be std::string.
This is the only way I can think of in the moment.
template<class T1=std::string, class T2=std::string, class T3=std::string>
RET_T function(std::string& source, const std::string& divide_token);
One (minor) drawback is, that the maximum number of substrings (==number of types) will be hardcoded.
The bigger problem in my eyes is, that I can not access the sequence of the types in my loop which will split and convert the substrings. e.g. The Nth substring has to be converted to the Nth type given. But how can I find out, what the Nth type is?
The second question would be: What shall the function return? It has to be some kind of collection which holds the right value of the right type on the right place.
Hm, I wonder if there is some boost / template / whatever magic which could do the job like I imagine. Any ideas or comments are very welcome, thank you!