Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorAlex Zolotarev <deathbaba@gmail.com>2011-05-01 06:09:04 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:16:53 +0300
commit66364da233cd1d8b07ee633e791addbb69ee9dfd (patch)
tree2e2f3255bc7cba6f883ddf6acccb9efad6777bc7 /base
parentab4c3806868847546b685121e5250cda1d90760e (diff)
Made templated method utils::to_string
Diffstat (limited to 'base')
-rw-r--r--base/base_tests/string_utils_test.cpp7
-rw-r--r--base/string_utils.cpp7
-rw-r--r--base/string_utils.hpp8
3 files changed, 14 insertions, 8 deletions
diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp
index 2e65aa389f..254e6f1d59 100644
--- a/base/base_tests/string_utils_test.cpp
+++ b/base/base_tests/string_utils_test.cpp
@@ -42,5 +42,12 @@ UNIT_TEST(to_double)
s = "-2";
TEST(utils::to_double(s, d), ());
TEST_ALMOST_EQUAL(-2.0, d, ());
+}
+UNIT_TEST(to_string)
+{
+ TEST_EQUAL(utils::to_string(-1), "-1", ());
+ TEST_EQUAL(utils::to_string(1234567890), "1234567890", ());
+ TEST_EQUAL(utils::to_string(0.56), "0.56", ());
+ TEST_EQUAL(utils::to_string(-100.2), "-100.2", ());
}
diff --git a/base/string_utils.cpp b/base/string_utils.cpp
index 53043ae3a1..edd76d1d5e 100644
--- a/base/string_utils.cpp
+++ b/base/string_utils.cpp
@@ -73,13 +73,6 @@ bool to_double(char const * s, double & d)
return false;
}
-string to_string(size_t i)
-{
- ostringstream ss;
- ss << i;
- return ss.str();
-}
-
void make_lower_case(string & s)
{
if (!s.empty())
diff --git a/base/string_utils.hpp b/base/string_utils.hpp
index 3d21062c5b..ae02c64c67 100644
--- a/base/string_utils.hpp
+++ b/base/string_utils.hpp
@@ -58,7 +58,13 @@ namespace utils
bool to_int64(char const * s, int64_t & i);
bool to_double(char const * s, double & d);
- string to_string(size_t i);
+ template <class T>
+ string to_string(T i)
+ {
+ ostringstream ss;
+ ss << i;
+ return ss.str();
+ }
inline bool to_int(string const & s, int & i) { return to_int(s.c_str(), i); }
inline bool to_uint64(string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); }