I don't want to take the time to look at your code.
Here's my personal itoa function, converted to your template function:
Code:
template <class int_type>
inline char* itoa_t(std::string& buf, const int_type nb)
{
std::string buffer;
int num = abs(nb);
const unsigned int numdigits = (log((float)num) / log(10.0f)) + 1;
unsigned int dig_buf;
for(int_type i = 1; i <= numdigits; ++i)
{
dig_buf = static_cast<int>(pow(10.0f, i-1));
buffer = (num % static_cast<int>(pow(10.0f, i))) / dig_buf + '0';
buf += buffer;
}
if(nb < 0)
{
buf += '-';
}
std::reverse(buf.begin(), buf.end());
return const_cast<char*>(buf.c_str());
}
Maybe you can get ideas from that?
It's longer and probably takes longer to execute, but I've never had to use itoa in a performace-critical part of code.