This commit is contained in:
2026-09-02 18:52:56 +03:00
parent d15928eb68
commit a49e7b5d5f
2 changed files with 98 additions and 65 deletions

View File

@@ -162,5 +162,66 @@ int main()
}
}
std::println("\n\n\n\n");
snplib::hmap<std::string> hm;
std::string k1{"k_int"}, k2{"k_str"}, k3("k_dbl");
int i1 = 10;
double f1 = 7.7;
std::string s1 = "test-str";
std::print("push element with key '{}' and value {}\t...", k1, i1);
ok = hm.push(k1, i1, std::tuple<long, double, float, long long>{});
if (!ok) {
std::println("cannot insert the value {}", i1);
} else {
std::println("OK");
}
std::print("push element with key '{}' and value {}\t...", k2, s1);
ok = hm.push(
k2, s1,
[](auto const& v) -> decltype(hm)::hmap_expected_t<const char*> {
return v.c_str();
// if (v) {
// return v.c_str();
// } else {
// return std::unexpected(v.error());
// }
},
[](auto const& v) -> decltype(hm)::hmap_expected_t<std::string> {
return std::string(v.value());
// if (v) {
// return std::string(v.value());
// } else {
// return std::unexpected(v.error());
// }
});
if (!ok) {
std::println("cannot insert the value {}", s1);
} else {
std::println("OK");
}
std::print("push element with key '{}' and value {}\t...", k3, f1);
ok = hm.push(k3, f1, std::tuple<long, int, float, long long>{});
if (!ok) {
std::println("cannot insert the value {}", f1);
} else {
std::println("OK");
}
std::println("\n");
std::print("get '{}'-element as double: ", k1);
auto f2 = hm.get<double>(k1);
if (f2) {
std::println("{}", f2.value());
} else {
std::println("FAIL");
}
return 0;
}