我什么时候使用node_type和std :: map :: insert? [英] When do I use node_type with std::map::insert?

查看:197
本文介绍了我什么时候使用node_type和std :: map :: insert?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经习惯了 std :: map 的现有接口。

插入元素会返回描述成功插入的bool,

以及插入元素所在位置的迭代器。

I'm accustomed to the existing interface of std::map.
Inserting elements returns a bool describing successful insertion,
as well the iterator as to where the inserted element would be.

template< class P >
std::pair<iterator,bool> insert( P&& value ); //(since C++11)

C ++ 17增加了类似的调用,但使用不同的类型名称:

C++17 adds what looks to be a similar call, but with different type names:

insert_return_type insert(node_type&& nh);   //(since C++17)

我试着查找 node_type 是,但主要是未指定:

I tried looking up what a node_type is, but it is primarily unspecified:

template</*unspecified*/>
class /*unspecified*/

为什么在C +中添加此功能+17,我什么时候会在较旧的电话上使用它?

推荐答案

这不仅仅是 std :: map ,类似的函数已添加到所有关联和无序关联容器中。它们在 [container.node] / 1 <标准中有解释。 / em>

It's not just std::map, similar functions have been added to all associative and unordered associative containers. They are explained in the standard in [container.node]/1


节点句柄是一个接受来自单个元素的所有权的对象关联容器(23.2.4)或无序关联容器(23.2.5)。它可用于将所有权转移到具有兼容节点的另一个容器
。具有兼容节点的容器具有相同的节点句柄类型。 ...

A node handle is an object that accepts ownership of a single element from an associative container (23.2.4) or an unordered associative container (23.2.5). It may be used to transfer that ownership to another container with compatible nodes. Containers with compatible nodes have the same node handle type. ...

上面的表格显示了具有兼容节点的容器。

The table following the section above shows the containers with compatible nodes.

节点处理接口允许您执行的操作是将元素(节点)从一个容器传输到另一个容器(兼容),而无需复制/移动元素。相反,由容器维护的各个内部节点作为一个整体进行传输。

What the node handle interface allows you to do is transfer elements (nodes) from one container to another (compatible) container without having to copy/move the elements. Instead, the individual internal nodes maintained by the container are transferred as a whole.

当处理包含不可复制,不可移动类型的容器时,这是必要的。 。

This becomes necessary when dealing with a container that contains a non-copyable, non-moveable type.

这篇关于我什么时候使用node_type和std :: map :: insert?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆