If I m constructing a non-trivial container like a custom map for example,
and want to share code between the emplace
and insert
functions, one approach would be to have the insert
function simply call emplace
with the supplied element as the argument.
eg.:
template<typename... args>
iterator emplace(int id, args &&... params)
{
// Do complex stuff here, get a location
*location = value_type(std::forward<args>(params) ...);
}
iterator insert(int id, const value_type &element)
{
emplace(id, element);
}
Which in the case of insert &
should simply call the copy constructor if I understand correctly?
However in the case of insert &&
it becomes a little more confusing:
iterator insert(int id, value_type &&element)
{
emplace(id, std::move(element));
}
<代码>std:move a. 折中元件,罚款,但将<代码>td:forward/code> 如何适当处理? e. 非属地的<代码> 数值_ 类型与非违约移动建筑商的,之上的<代码>emplace建筑线将正确地称作移动建筑商?