29 using Duration = std::remove_cvref_t<
decltype(t)>;
30 auto trim = s.find_first_not_of(
"+0 ");
31 if (
trim == std::string_view::npos)
33 s.remove_prefix(
trim);
34 const auto *
val_end = s.data() + s.size();
37 if (res.ec != std::errc())
39 "Invalid value '" + std::string(res.ptr,
val_end) +
"' for type '" +
41 "': " + std::make_error_code(res.ec).message(),
44 auto end =
remainder.find_first_of(
"+-0123456789. ");
45 std::string_view units =
remainder.substr(0, end);
46 using std::chrono::duration;
47 auto cast = [](
auto t) {
return std::chrono::round<Duration>(t); };
48 if (units ==
"s" || units.empty())
49 t += cast(duration<
double, std::ratio<1, 1>>{value});
50 else if (units ==
"ms")
51 t += cast(duration<
double, std::ratio<1, 1'000>>{value});
52 else if (units ==
"us" || units ==
"µs")
53 t += cast(duration<
double, std::ratio<1, 1'000'000>>{value});
54 else if (units ==
"ns")
55 t += cast(duration<
double, std::ratio<1, 1'000'000'000>>{value});
56 else if (units ==
"min")
57 t += cast(duration<
double, std::ratio<60, 1>>{value});
58 else if (units ==
"h")
59 t += cast(duration<
double, std::ratio<3'600, 1>>{value});
62 "Invalid units '" + std::string(units) +
"' for duration", units);
63 if (end == std::string_view::npos)