From 327e1244e44f79f418518c0d1e8f2fced7b63d85 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Tue, 11 Feb 2014 18:12:00 +0100 Subject: [PATCH] Review to_string --- tstl/include/string.hpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tstl/include/string.hpp b/tstl/include/string.hpp index ad4cc53f..a0300207 100644 --- a/tstl/include/string.hpp +++ b/tstl/include/string.hpp @@ -354,10 +354,10 @@ std::vector> split(const std::basic_string& s){ } template -std::string to_string(T value); +std::string to_string(const T& value); template<> -inline std::string to_string(uint64_t value){ +inline std::string to_string(const uint64_t& value){ if(value == 0){ return "0"; } @@ -366,10 +366,11 @@ inline std::string to_string(uint64_t value){ char buffer[20]; int i = 0; + auto rem = value; - while(value != 0){ - buffer[i++] = '0' + value % 10; - value /= 10; + while(rem != 0){ + buffer[i++] = '0' + rem % 10; + rem /= 10; } --i; @@ -382,7 +383,7 @@ inline std::string to_string(uint64_t value){ } template<> -inline std::string to_string(int64_t value){ +inline std::string to_string(const int64_t& value){ if(value < 0){ std::string s("-"); s += to_string(static_cast(value)); @@ -392,6 +393,11 @@ inline std::string to_string(int64_t value){ } } +template<> +inline std::string to_string(const unsigned int& value){ + return to_string(static_cast(value)); +} + } //end of namespace std #endif