#ifndef TOOLKIT_H #define TOOLKIT_H #include #include #include #include //use for to_chars constexpr size_t buffer_size = 32; namespace toolkit{ //number to std::string; template std::expected itos(T value){ 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); } 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