1478 using Quantity_t = Quantity;
1479 using value_t =
typename Quantity_t::value_t;
1480 using unit_t =
typename Quantity_t::unit_t;
1481 using baseunit_t =
typename unit_t::baseunit_t;
1486 using PrefixMap_t = std::map<std::string, value_t>;
1487 using PrefixValue_t =
typename PrefixMap_t::value_type;
1488 static PrefixMap_t
const factors{PrefixValue_t{
"a"s, 1
e-18},
1489 PrefixValue_t{
"f"s, 1e-15},
1490 PrefixValue_t{
"p"s, 1e-12},
1491 PrefixValue_t{
"n"s, 1e-09},
1492 PrefixValue_t{
"u"s, 1e-06},
1493 PrefixValue_t{
"m"s, 1e-03},
1494 PrefixValue_t{
"c"s, 1e-02},
1495 PrefixValue_t{
"d"s, 1e-01},
1496 PrefixValue_t{
""s, 1e+00},
1497 PrefixValue_t{
"da"s, 1e+01},
1498 PrefixValue_t{
"h"s, 1e+02},
1499 PrefixValue_t{
"k"s, 1e+03},
1500 PrefixValue_t{
"M"s, 1e+06},
1501 PrefixValue_t{
"G"s, 1e+09},
1502 PrefixValue_t{
"T"s, 1e+12},
1503 PrefixValue_t{
"P"s, 1e+15},
1504 PrefixValue_t{
"E"s, 1e+18}};
1505 static auto const composePrefixPattern = [](
auto b,
auto e) -> std::string {
1506 std::string pattern =
"(";
1508 pattern += b->first;
1511 pattern += b->first;
1514 return pattern +=
")";
1516 static std::string
const prefixPattern = composePrefixPattern(factors.begin(), factors.end());
1519 std::regex
const unitPattern{
"[[:blank:]]*(" + prefixPattern +
"?" +
1522 std::smatch unitMatch;
1523 if (!std::regex_search(str, unitMatch, unitPattern)) {
1524 if (!unitOptional) {
1525 throw MissingUnit(
"Unit is mandatory and must derive from '" +
1528 return {str, value_t{1}};
1536 auto const iFactor = factors.find(unitMatch.str(2U));
1537 if (iFactor == factors.end()) {
1538 throw InvalidUnitPrefix(
"Unit '" + unitMatch.str(1U) +
"' has unsupported prefix '" +
1539 unitMatch.str(2U) +
"' (parsing '" + str +
"')");
1542 return {str.substr(0U, str.length() - unitMatch.length()),
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.