8

During a random documentation check on cppreference.com i noticed new member function overloads for some containers taking as a parameter what happens to be a new standard type from C++17 called a Node Handle.

Now the documentation page of node handles on the same site gives multiple details and technical behaviors on how this work, but it doesn't really convey properly the general idea and purpose of this new type.

Hence the question, what is a Node Handle ?

Drax
  • 12,682
  • 7
  • 45
  • 85

2 Answers2

7

Node based containers have the potential to support easy extraction and merger. It would be as simple as unlinking the internal nodes from set A, and placing them into set B. This is different to moving Keys and Values out of the container, in that we aren't left with "empty" nodes that need cleanup, nor are we allocating a new node when we already have a perfectly good one that can just be moved itself.

To facilitate this new API for the containers the standard needed a way to let client programmers get a hold of those nodes, without breaking encapsulation. Hence the handle.

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
5

The idea of a node handle is that refers to a 'node' of the map or set which is disembodied from the map itself.

Its purpose is to be able to move items from one map to another without invoking any overhead for copying or moving keys or data.

An example here:

http://en.cppreference.com/w/cpp/container/map/extract

Richard Hodges
  • 68,278
  • 7
  • 90
  • 142