From d1e2b4f904266c94f4ebf9fc5c95d495c95b0d5c Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 17 Oct 2017 22:06:13 +0200 Subject: Improve stringToFloatVector to match stringToDoubleVector --- src/Utilities.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Utilities.cpp b/src/Utilities.cpp index c90e67b..2ae1b66 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -66,14 +66,10 @@ double stringToDouble(const std::string& s) template<> float stringTo(const std::string& s) { return stringToFloat(s); } template<> double stringTo(const std::string& s) { return stringToDouble(s); } -std::vector stringToFloatVector(const std::string &s) -{ - return stringToVector(s); -} - -std::vector stringToDoubleVector(const std::string &s) +template +std::vector stringToNumericVector(const std::string &s) { - std::vector out; + std::vector out; out.reserve(100); std::istringstream iss; iss.imbue(std::locale::classic()); @@ -85,7 +81,7 @@ std::vector stringToDoubleVector(const std::string &s) std::string t = s.substr(current, next - current); iss.str(t); iss.clear(); - double f; + T f; iss >> f; out.push_back(f); current = next + 1; @@ -94,6 +90,15 @@ std::vector stringToDoubleVector(const std::string &s) return out; } +std::vector stringToFloatVector(const std::string &s) +{ + return stringToNumericVector(s); +} +std::vector stringToDoubleVector(const std::string &s) +{ + return stringToNumericVector(s); +} + template std::vector stringToVector(const std::string& s) { -- cgit v1.2.3