When do I use node_type with std::map::insert?

前端 未结 2 1488
逝去的感伤
逝去的感伤 2021-02-14 01:14

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 t

2条回答
  •  萌比男神i
    2021-02-14 01:45

    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

    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.

提交回复
热议问题