View Single Post
  #6  
Old 10-08-2014, 11:18 AM
CoryWalker
Fire Beetle
 
Join Date: Oct 2014
Posts: 23
Default

C++11 is still young as an ISO standard. I'm sure all platforms will catch up in a few years.

If you look in debug.cpp, line 369 you will notice that there is a little bit of casting going on to a "long long" because VS 2010 didn't have the standard fully implemented either at the time of writing. I think an opportunity exists to make the code cleaner and more portable with a single refactoring.

It seems kind of silly that the problem of converting an integer to a string is a problem with modern day development systems. Still, here is what I would propose.

Create a set of static, overloaded methods:

static string ConvertToString (int param);
static string ConvertToString (long long param);

The following function body converts an integer to a string using the Standard C Library:

char param_chars[16];
sprintf(param_chars, "%d", param);
std::string paramString (param_chars);
return paramString;

You will immediately notice that I have little experience with C++. However, I believe this will compile and run anywhere and we don't have to do any casting at all.

Later on - when C++11 is fully implemented everywhere - we can replace it with:

return std::to_string(param);

Last edited by CoryWalker; 10-08-2014 at 05:07 PM.. Reason: Fixed code for variable param_chars.
Reply With Quote