I don't want to take the time to look at your code.
Here's my personal itoa function, converted to your template function:
Maybe you can get ideas from that?
template <class int_type>
inline char* itoa_t(std::string& buf, const int_type nb)
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 += '-';
It's longer and probably takes longer to execute, but I've never had to use itoa in a performace-critical part of code.