add num type(BIN HEX etc..)
This commit is contained in:
parent
05eb9e5e6f
commit
53bb8c0c5d
@ -29,8 +29,15 @@ concept _num_type = requires {
|
||||
|
||||
namespace toolkit
|
||||
{
|
||||
enum class num_type{
|
||||
BIN,
|
||||
HEX,
|
||||
OCT,
|
||||
DEC
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::expected<std::string, std::string> to_string(T value)
|
||||
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>)
|
||||
{
|
||||
@ -50,7 +57,7 @@ namespace toolkit
|
||||
}
|
||||
|
||||
template <typename T = double> // requires std::is_same_v<T, std::string>
|
||||
std::expected<T, std::string> stoi(const std::string &str)
|
||||
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);
|
||||
@ -63,7 +70,7 @@ namespace toolkit
|
||||
|
||||
template <typename T>
|
||||
requires std::is_same_v<std::string, T> || std::is_same_v<const char *, T>
|
||||
std::string replace_string(const std::string &str, T d, T e)
|
||||
inline std::string replace_string(const std::string &str, T d, T e)
|
||||
{
|
||||
std::string result = str;
|
||||
if (d == e)
|
||||
@ -93,7 +100,7 @@ namespace toolkit
|
||||
template <typename T = std::string>
|
||||
requires std::is_same_v<T, std::string> ||
|
||||
std::is_same_v<T, std::string_view>
|
||||
std::vector<T> split(T str, T d)
|
||||
inline std::vector<T> split(T str, T d)
|
||||
{
|
||||
auto v = views::split(str, d) | views::transform([](auto word)
|
||||
{ return T(word.begin(), word.end()); });
|
||||
|
Loading…
Reference in New Issue
Block a user