+unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
+{
+ for (const auto& gen : generators) {
+ const std::string& unit = std::get<0>(gen);
+ double value = std::get<1>(gen);
+ const int base = std::get<2>(gen);
+ const bool abbrev = std::get<3>(gen);
+ double mult;
+ std::vector<std::string> prefixes;
+ switch (base) {
+ case 2:
+ mult = 1024.0;
+ prefixes = abbrev ? std::vector<std::string>{"Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
+ : std::vector<std::string>{"kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"};
+ break;
+ case 10:
+ mult = 1000.0;
+ prefixes = abbrev ? std::vector<std::string>{"k", "M", "G", "T", "P", "E", "Z", "Y"}
+ : std::vector<std::string>{"kilo", "mega", "giga", "tera", "peta", "exa", "zeta", "yotta"};
+ break;
+ default:
+ THROW_IMPOSSIBLE;
+ }
+ emplace(unit, value);
+ for (const auto& prefix : prefixes) {
+ value *= mult;
+ emplace(prefix + unit, value);
+ }
+ }
+}
+