Can I put objects or just pairs to display objects?

I am using C ++ 11 and gcc-4.7.0. I am looking for an STL solution.

I would like to have an unsorted multimap that contains myClass objects with short strings as keys. Emplace looks like a good way to put objects into a map as they are created, but I'm not sure if it can do this, or if it will only build a key / object pair. It should be valid:

table.emplace(myKey, myClass(arg1, arg2, arg3));

But would it be more efficient to do the following, and is this even valid code?

table.emplace(myKey, arg1, arg2, arg3);
+4
source share
1 answer

According to this , it gcc-4.7does not fully support emplace().

gcc-4.8 emplace(), :

table.emplace(std::piecewise_construct, std::forward_as_tuple(myKey), std::forward_as_tuple(arg1, arg2, arg3));

table.emplace(myKey, arg1, arg2, arg3); // Does not work.

forward rvalue, std::move() .

, , .

std::piecewise_construct std::pair. .

emplace() . , , , . . .

Zeta, forward.

+6

Source: https://habr.com/ru/post/1533024/


All Articles