Why does Clang 12 refuse to initialize aggregates in the C++20 way?

This is a C++20 feature that allows aggregate initialization through the standard constructor syntax, rather than the typical braced-list initialization syntax. (Note that this only works if the parameters cannot be used in a valid call to a default or copy/move constructor. If they could, that would be called instead of performing aggregate initialization.) According … Read more

std::map emplace without copying value

The arguments you pass to map::emplace get forwarded to the constructor of map::value_type, which is pair<const Key, Value>. So you can use the piecewise construction constructor of std::pair to avoid intermediate copies and moves. std::map<int, Foo> m; m.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(2.3, “hello”)); Live demo