Skip to content
Snippets Groups Projects
Commit 6356c1b4 authored by Tom Fischer's avatar Tom Fischer
Browse files

[BL] Use std::to_string direct instead of a wrapper.

parent e3c25372
No related branches found
No related tags found
No related merge requests found
......@@ -90,7 +90,7 @@ int writeMeshOutput(std::string const& input_file,
addObjectsToMesh(*swmm, mesh, FileIO::SwmmObject::LINK, i);
MeshLib::IO::VtuInterface vtkio(&mesh, 0, false);
std::string name(basename + BaseLib::tostring(i) + extension);
std::string name(basename + std::to_string(i) + extension);
vtkio.writeToFile(name);
}
return 0;
......
......@@ -13,11 +13,11 @@
#include <algorithm>
#include <boost/optional.hpp>
#include <cassert>
#include <string>
#include <typeindex>
#include <typeinfo>
#include "Error.h"
#include "StringTools.h"
namespace BaseLib
{
......@@ -94,7 +94,7 @@ void insertIfTypeIndexKeyUniqueElseError(Map& map, Key const& key,
if (!inserted.second)
{ // insertion failed, i.e., key already exists
OGS_FATAL("{:s} Key `{:s}' already exists.", error_message,
tostring(key.hash_code()));
std::to_string(key.hash_code()));
}
}
......@@ -110,8 +110,7 @@ void insertIfKeyUniqueElseError(Map& map, Key const& key, Value&& value,
auto const inserted = map.emplace(key, std::forward<Value>(value));
if (!inserted.second)
{ // insertion failed, i.e., key already exists
OGS_FATAL("{:s} Key `{:s}' already exists.", error_message,
tostring(key));
OGS_FATAL("{:s} Key `{:s}' already exists.", error_message, key);
}
}
......@@ -130,14 +129,14 @@ void insertIfKeyValueUniqueElseError(Map& map, Key const& key, Value&& value,
if (std::find_if(map.cbegin(), map.cend(), value_compare) != map.cend())
{
OGS_FATAL("{:s} Value `{:s}' already exists.", error_message,
tostring(value));
std::to_string(value));
}
auto const inserted = map.emplace(key, std::forward<Value>(value));
if (!inserted.second)
{ // insertion failed, i.e., key already exists
OGS_FATAL("{:s} Key `{:s}' already exists.", error_message,
tostring(key));
std::to_string(key));
}
}
......@@ -153,8 +152,15 @@ typename Map::mapped_type& getOrError(Map& map, Key const& key,
auto it = map.find(key);
if (it == map.end())
{
OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message,
tostring(key));
if constexpr (std::is_convertible<Key, std::string>::value)
{
OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message, key);
}
else
{
OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message,
std::to_string(key));
}
}
return it->second;
......@@ -167,8 +173,15 @@ typename Map::mapped_type const& getOrError(Map const& map, Key const& key,
auto it = map.find(key);
if (it == map.end())
{
OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message,
tostring(key));
if constexpr (std::is_convertible<Key, std::string>::value)
{
OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message, key);
}
else
{
OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message,
std::to_string(key));
}
}
return it->second;
......
......@@ -82,11 +82,6 @@ void simplify(std::string &str)
);
}
std::string const& tostring(std::string const& value)
{
return value;
}
std::string format(const char* format_str, ... )
{
va_list args;
......
......@@ -72,14 +72,6 @@ void trim(std::string &str, char ch=' ');
*/
void simplify(std::string &str);
//! Method for handling conversion to string uniformly across all types and std::string; see std::string overload below.
template<typename T> std::string tostring(T const& value)
{
return std::to_string(value);
}
//! \overload
std::string const& tostring(std::string const& value);
//! Returns a random string of the given length containing just a-z,A-Z,0-9
std::string randomString(std::size_t length);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment