Hi! everyone,
I have 3 functions that reads some data from a string and stores it in a vector list. The 3 functions are for storing in a string vector, int vector and a float vector. I want to make these 3 functions as a general templatised version, but was unable to do it. I am getting compile errors.
Can anyone suggest a way to do this?
These are the 3 functions.
void ReadStringData( const string &readstring, std::vector<string> &_list );
void ReadFloatData( string &readstring, std::vector<float> &_list);
void ReadIntData( str &readstring, std::vector<uint32_t> &_list);
I have created a generic template function but can't seem to make it work.
template<typename T1,typename T2>
void ReadData(const T1& data, T2& list)
{
int32_t lastPos = 0;
for (size_t i=0; i<data.length(); ++i)
{
int32_t pos = data.find(delimiter_colon, 0, lastPos);
if (0 == data.length())
{
break;
}
if (1 != pos)
{
string temp = data.substr(lastPos, pos-lastPos);
list.push_back(temp);
lastPos = pos+1;
}
}
}
How do i call this function with proper arguments? Any inputs will be very helpful.
Cheers!
Happy holidays.