mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
optimised conversions from string to numerical types
This commit is contained in:
parent
9484934a8a
commit
4d25722736
@ -26,3 +26,21 @@ using namespace Latan;
|
||||
const string Env::fullName = PACKAGE_STRING;
|
||||
const string Env::name = PACKAGE_NAME;
|
||||
const string Env::version = PACKAGE_VERSION;
|
||||
|
||||
template <>
|
||||
float Latan::strTo<float>(const string &str)
|
||||
{
|
||||
return strtof(str.c_str(), (char **)NULL);
|
||||
}
|
||||
|
||||
template <>
|
||||
double Latan::strTo<double>(const string &str)
|
||||
{
|
||||
return strtod(str.c_str(), (char **)NULL);
|
||||
}
|
||||
|
||||
template <>
|
||||
int Latan::strTo<int>(const string &str)
|
||||
{
|
||||
return (int)(strtol(str.c_str(), (char **)NULL, 10));
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ namespace Env
|
||||
|
||||
// string conversions
|
||||
template <typename T>
|
||||
T strTo(std::string str)
|
||||
T strTo(const std::string &str)
|
||||
{
|
||||
T buf;
|
||||
std::istringstream stream(str);
|
||||
@ -59,8 +59,16 @@ T strTo(std::string str)
|
||||
return buf;
|
||||
}
|
||||
|
||||
//// optimized specializations
|
||||
template <>
|
||||
float strTo<float>(const std::string &str);
|
||||
template <>
|
||||
double strTo<double>(const std::string &str);
|
||||
template <>
|
||||
int strTo<int>(const std::string &str);
|
||||
|
||||
template <typename T>
|
||||
std::string strFrom(T x)
|
||||
std::string strFrom(const T x)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user