Sync from fork #2

Open
CommanderRedYT wants to merge 5 commits from CommanderRedYT/main into main
2 changed files with 21 additions and 0 deletions
Showing only changes of commit 2864a39c10 - Show all commits

View File

@@ -94,4 +94,20 @@ template<> inline std::expected<uint64_t, std::string> fromString<uint64_t>(std:
return std::unexpected(fmt::format("invalid uint64_t {}", str));
return val;
}
template<> inline std::expected<float, std::string> fromString<float>(std::string_view str)
{
float val;
if (std::sscanf(str.data(), "%f", &val) != 1)
return std::unexpected(fmt::format("invalid float {}", str));
return val;
}
template<> inline std::expected<double, std::string> fromString<double>(std::string_view str)
{
double val;
if (std::sscanf(str.data(), "%lf", &val) != 1)
return std::unexpected(fmt::format("invalid double {}", str));
return val;
}
} // namespace cpputils