A
Andrea Crotti
I have the following problem, I have a vector of chars and I want to
represent it as
a vector of ints.
So I added another parameter in the template function which defaults
to T (gcc needs the new 0++x standard for this) but still it doesn't
work
Here below the code, the function at run time is correct
"vectorToString<char, unsigned int>"
but I always see printed out the char representation.
Anything else wrong?
template <typename T, typename Repr=T>
std::string vectorToString(const std::vector<T>& inp) {
std::string empty("[]");
if (inp.size() == 0)
return empty;
std:stringstream os;
os << "[";
size_t i;
for (i=0; i < (inp.size()-1); ++i) {
os << static_cast<Repr> (inp) << ",";
}
os << static_cast<Repr> (inp) << "]";
return os.str();
}
Thanks,
Andrea
represent it as
a vector of ints.
So I added another parameter in the template function which defaults
to T (gcc needs the new 0++x standard for this) but still it doesn't
work
Here below the code, the function at run time is correct
"vectorToString<char, unsigned int>"
but I always see printed out the char representation.
Anything else wrong?
template <typename T, typename Repr=T>
std::string vectorToString(const std::vector<T>& inp) {
std::string empty("[]");
if (inp.size() == 0)
return empty;
std:stringstream os;
os << "[";
size_t i;
for (i=0; i < (inp.size()-1); ++i) {
os << static_cast<Repr> (inp) << ",";
}
os << static_cast<Repr> (inp) << "]";
return os.str();
}
Thanks,
Andrea