#ifndef TOOLKIT_H #define TOOLKIT_H #include #include #include #include #include #include //use for to_chars constexpr size_t buffer_size = 32; template concept _num_type = requires { std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v; }; namespace toolkit{ template std::expected to_string(T value){ if constexpr (std::is_same_v || std::is_same_v || std::is_same_v){ 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); } else if constexpr (std::is_same_v::type, char *>) { return std::to_string(value); } } template// requires std::is_same_v std::expected 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 value; } } #endif