Template functions with STL in gcc 3.2.2
Rob Emanuele
rje@cyan.com
Sat Jul 26 20:43:00 GMT 2003
Hello,
I've got two template functions below. They compile and work under Visual
C++ (which does let some weird code through). Using GCC 3.2.2 the second
fucntion will not compile. The line "T::const_iterator it = group.begin();"
shows a "parse error befire '=' token".
Any ideas why it can't compile that?
Thanks,
Rob
typedef std::vector<std::string> StringVector;
typedef std::list<std::string> StringList;
template bool GetStringGroup<StringList>(const std::string& s, StringList&
group, char sep);
template bool GetStringGroup<StringVector>(const std::string& s,
StringVector& group, char sep);
template <typename T> bool GetStringGroup(const std::string& s, T& group,
char sep)
{
bool ret = false;
std::string::size_type oldpos = 0, newpos = 0;
if (!(s.empty()))
{
do
{
newpos = s.find(',',oldpos);
group.push_back(s.substr(oldpos,newpos));
if (newpos != s.npos)
oldpos = newpos+1;
}
while(newpos != s.npos);
ret = true;
}
return ret;
}
template bool GetStringGroupAsString<StringList>(const StringList& group,
std::string& s, char sep);
template bool GetStringGroupAsString<StringVector>(const StringVector&
group, std::string& s, char sep);
template <typename T> bool GetStringGroupAsString(const T& group,
std::string& s, char sep)
{
T::const_iterator it = group.begin();
bool fst = true;
while (it != group.end())
{
if (!fst)
s += ",";
s+= (*it).c_str();
it++;
}
return true;
}
More information about the Gcc
mailing list