ini逻辑 占位
This commit is contained in:
@@ -5,41 +5,43 @@
|
||||
#include <expected>
|
||||
#include <chrono>
|
||||
|
||||
namespace util{
|
||||
|
||||
template <typename T>
|
||||
inline std::expected<std::string, std::string> to_string(T value)
|
||||
namespace util
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
inline std::expected<std::string, std::string> to_string(T value)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, int> || std::is_same_v<T, float> || std::is_same_v<T, double>)
|
||||
{
|
||||
char buffer[buffer_size];
|
||||
auto res = std::to_chars(buffer, buffer + buffer_size, value);
|
||||
if (res.ec != std::errc())
|
||||
{
|
||||
char buffer[buffer_size];
|
||||
auto res = std::to_chars(buffer, buffer + buffer_size, value);
|
||||
if (res.ec != std::errc())
|
||||
{
|
||||
return std::unexpected(std::make_error_code(res.ec).message());
|
||||
}
|
||||
return std::string(buffer, res.ptr - buffer);
|
||||
}
|
||||
return std::string(buffer, res.ptr - buffer);
|
||||
}
|
||||
else if constexpr (std::is_same_v<typename std::remove_const<T>::type,
|
||||
char *>)
|
||||
char *>)
|
||||
{
|
||||
return std::to_string(value);
|
||||
return std::to_string(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T = double> // requires std::is_same_v<T, std::string>
|
||||
inline std::expected<T, std::string> stoi(const std::string &str)
|
||||
{
|
||||
template <typename T = double> // requires std::is_same_v<T, std::string>
|
||||
inline std::expected<T, std::string> stoi(const std::string &str)
|
||||
{
|
||||
T value;
|
||||
auto res = std::from_chars(str.c_str(), str.c_str() + str.size(), value);
|
||||
if (res.ec != std::errc())
|
||||
{
|
||||
return std::unexpected(std::make_error_code(res.ec).message());
|
||||
return std::unexpected(std::make_error_code(res.ec).message());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string get_time_now(){
|
||||
inline std::string get_time_now()
|
||||
{
|
||||
auto time_now = std::chrono::system_clock::now();
|
||||
auto now_c = std::chrono::system_clock::to_time_t(time_now);
|
||||
char buffer[32];
|
||||
@@ -52,9 +54,6 @@ inline std::expected<T, std::string> stoi(const std::string &str)
|
||||
result = string::replace_string(result, "\n", "");
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user