Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Node Handle?

Tags:

c++

c++17

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 ?

like image 327
Drax Avatar asked Dec 07 '16 11:12

Drax


People also ask

What is a node handle in C++?

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.

What does Ros :: init do?

Initializing the node through a call to one of the ros::init() functions. This provides command line arguments to ROS, and allows you to name your node and specify other options. Starting the node is most often done through creation of a ros::NodeHandle, but in advanced cases can be done in different ways.

What is namespace in Ros?

Graph Resource Names are an important mechanism in ROS for providing encapsulation. Each resource is defined within a namespace, which it may share with many other resources. In general, resources can create resources within their namespace and they can access resources within or above their own namespace.


2 Answers

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.

like image 128
StoryTeller - Unslander Monica Avatar answered Oct 23 '22 12:10

StoryTeller - Unslander Monica


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

like image 35
Richard Hodges Avatar answered Oct 23 '22 13:10

Richard Hodges