kingwales
kingwales

Reputation: 139

How to understand this std::bind usage

I am trying to understand this usage of std::bind(). For this example:

std::bind(&TrtNodeValidator::IsTensorRTCandidate, &validator, std::placeholders::_1)

They are trying to bind the function TrtNodeValidator::IsTensorRTCandidate(). However, according to the definition of this API:

Status TrtNodeValidator::IsTensorRTCandidate(const Node* node);

It only accepts one parameter. Why do they still need &validator when there exits std::placeholders::_1?

Upvotes: 1

Views: 72

Answers (1)

Drew Dormann
Drew Dormann

Reputation: 63725

TrtNodeValidator::IsTensorRTCandidate() is a non-static member function.

Aside from its explicit parameters, it requires a TrtNodeValidator* to become its implicit this parameter.

This usage:

std::bind(&TrtNodeValidator::IsTensorRTCandidate, &validator, 
          std::placeholders::_1)

will produce a callable object that then calls:

(&validator)->IsTensorRTCandidate(std::placeholders::_1)

Upvotes: 7

Related Questions