Commit 5f6d7696 authored by Alexander Lapshin's avatar Alexander Lapshin

.

parent 303a6372
......@@ -20,7 +20,7 @@
static std::string ToStr(const int arg, const int leading_zeros)
{
std::ostringstream ss;
if(leading_zeros) {
if (leading_zeros) {
ss << std::setw(leading_zeros) << std::setfill('0');
}
ss << arg;
......@@ -37,7 +37,7 @@ static std::string ToStr(const size_t arg, const int leading_zeros)
return ss.str();
}
template <typename T>
template <typename T>
void hangle_to_chars_error(const std::to_chars_result& res, const T& arg)
{
if (res.ec == std::errc::invalid_argument) {
......@@ -51,37 +51,18 @@ void hangle_to_chars_error(const std::to_chars_result& res, const T& arg)
throw Exp() << "failed to convert value [" << arg << "] to string";
}
static std::string ToStr(const int arg)
{
std::array<char, 32> buf;
const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), arg);
if (res.ec == std::errc()) {
return std::string(buf.data(), res.ptr - buf.data());
}
hangle_to_chars_error(res, arg);
return "";
}
static std::string ToStr(const size_t arg)
static std::string ToStr(const double value, const int precision = 0)
{
std::array<char, 32> buf;
const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), arg);
if (res.ec == std::errc()) {
return std::string(buf.data(), res.ptr - buf.data());
std::ostringstream ss;
if (precision) {
ss << std::setprecision(precision);
}
hangle_to_chars_error(res, arg);
return "";
ss << value;
return ss.str();
}
static std::string ToStr(const double arg)
template <typename T>
static std::string ToStr(const T arg)
{
std::array<char, 32> buf;
......@@ -96,13 +77,35 @@ static std::string ToStr(const double arg)
return "";
}
static std::string ToStr(const double value, const int precision)
{
std::ostringstream ss;
ss << std::setprecision(precision);
ss << value;
return ss.str();
}
// static std::string ToStr(const size_t arg)
// {
// std::array<char, 32> buf;
//
// const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), arg);
//
// if (res.ec == std::errc()) {
// return std::string(buf.data(), res.ptr - buf.data());
// }
//
// hangle_to_chars_error(res, arg);
//
// return "";
// }
//
// static std::string ToStr(const double arg)
// {
// std::array<char, 32> buf;
//
// const auto res = std::to_chars(buf.data(), buf.data() + buf.size(), arg);
//
// if (res.ec == std::errc()) {
// return std::string(buf.data(), res.ptr - buf.data());
// }
//
// hangle_to_chars_error(res, arg);
//
// return "";
// }
static void string_replace(std::string& str, const std::string& from, const std::string& to)
{
......@@ -397,7 +400,7 @@ std::vector<T> map_keys(const std::map<T, T2>& map)
std::vector<T> result;
result.reserve(map.size());
for (const auto& it: map) {
for (const auto& it : map) {
result.push_back(it.first);
}
......@@ -425,4 +428,3 @@ bool in_array(const std::vector<T>& src, T subject)
{
return std::find(std::begin(src), std::end(src), subject) != std::end(src);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment