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
?
CodePudding user response:
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)