Closed
Description
Hello community,
I am trying to translate this piece of C++ code into Cppfront:
template<class AssocContainer, class Func = std::plus<>>
void
combine_maps(AssocContainer& map1, const AssocContainer& map2, Func func = {})
{
for (const auto& [k, v] : map2)
map1[k] = func(map1[k], v);
}
And I tried this:
combine_maps:<AssocContainer, Func: type = std::plus<>>(inout map1: AssocContainer, map2: AssocContainer, func: Func = ()) = {
for map2 do(kv) {
map1[kv.first] = func(map1[kv.first], kv.second);
}
}
My questions are simple:
- is there a way to default the template parameter to
std::plus<>
as in plain C++? - is there a way to bind key and value in Cpp2 in a similar way to a structured binding? Maybe with pattern matching of some kind?
- can I default
func: Func = ()
parameter? It seems to emit code where there isconst Func & func = <empty here>
Thank you for your time and support to everyone.