use of emplace(args&& …) in associative containers

天涯浪子 提交于 2019-12-04 12:16:10

So the new emplace doesn't do any piece wise construction like boost ?

What you refer to a "piece wise construction" is not what the standard refers to as piecewise construction, which is:

m.emplace(std::piecewise_construct,
          std::forward_as_tuple<A1>(arg1),
          std::forward_as_tuple<A2,A3,A4>(arg2, arg3, arg4));

This does exactly what you want, forwarding the tuples of args to the first and second pair members (but be aware that with GCC 4.6 this requires an accessible copy constructor for each argument type, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51183 -- this requirement is fixed for GCC 4.7 by using delegating constructors, not supported by GCC 4.6)

This is indeed a defect in the standard, it is addressed at length in N3178.

To quote,

the only way to construct an object of value_type is to supply exactly two arguments for Key and Value, a pair, or a piecewise_construct_t followed by two tuples. The original emplace() proposal would have allowed you to specify a Key value followed by any number of constructor arguments for Value. When we removed the variadic constructor to pair, this ability went away

...

the status quo is to use piecewise_construct_t if you want to construct an object.

It was closed as "NAD"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!