add the pushWithCnv method to the HeterogenMap class
This commit is contained in:
@@ -128,5 +128,31 @@ int main()
|
||||
std::println("hmap_move.size() = {}", hmap_move.size());
|
||||
std::println("hmap_copy.size() = {}", hmap_copy.size());
|
||||
|
||||
std::println("\n{:*^80}", " hmap with custom conv funcs ");
|
||||
|
||||
hmap.pushWithCnv(
|
||||
"str_cst", std::string{"ABC"}, [&s](std::string const& v) { return s.c_str(); },
|
||||
[&s](const char* p) {
|
||||
s = p;
|
||||
return s;
|
||||
});
|
||||
|
||||
auto ptr = hmap.get<const char*>("str_cst");
|
||||
if (ptr) {
|
||||
std::println("ptr = {}", ptr.value());
|
||||
} else {
|
||||
std::println("cannot get PTR");
|
||||
}
|
||||
|
||||
// std::string pp = "EEEE";
|
||||
// auto err = hmap.set("str_cst", pp.c_str());
|
||||
const char* pp = "EEEE";
|
||||
auto err = hmap.set("str_cst", pp);
|
||||
if (err) {
|
||||
std::println("cannot set 'str_cst'");
|
||||
} else {
|
||||
std::println("s = {}", s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user