АВ
Size: a a a
АВ
ПК
using Item = map<string, variant<string, double>>;
Item item = {{"a", 1}};
if (item.find("b") == item.end()) {
item["b"] = 0;
}
BB
using Item = map<string, variant<string, double>>;
Item item = {{"a", 1}};
if (item.find("b") == item.end()) {
item["b"] = 0;
}
ПК
using Item = map<string, variant<string, double>>;
Item item = {{"a", 1}};
if (item.find("b") == item.end()) {
item["b"] = 0;
}
t
D
АВ
D
insert_if_absent
M
using Item = map<string, variant<string, double>>;
Item item = {{"a", 1}};
if (item.find("b") == item.end()) {
item["b"] = 0;
}
item["b"];
АВ
item["b"];
D
АВ
D
D
item["b"];
t
item["b"];
D
AS
M
void checkItem(std::string key) {
try {
item[key];
std::get<double>(item[key]);
}
catch(const std::bad_variant_access&) {
item[key] = 0; // set default
}
}
АВ