This code is from C++ primer p.446:
return hash<string>() (sd.isbn());
I don't understand the return expression with two pairs of parentheses. There's no similar syntax in front of the book.
print(funcwrapper(3, 2)) So what does the first example using two pairs of parentheses accomplish? The use of a double parentheses is actually an indicator of one of Python's coolest features - and that is that functions are themselves, objects!
One approach to check balanced parentheses is to use stack. Each time, when an open parentheses is encountered push it in the stack, and when closed parenthesis is encountered, match it with the top of stack and pop it. If stack is empty at the end, return Balanced otherwise, Unbalanced.
The balanced parenthesis means that when the opening parenthesis is equal to the closing parenthesis, then it is a balanced parenthesis.
std::hash
is a class type. What you are doing here is constructing a temporary std::hash
with hash<string>()
and then (sd.isbn())
calls the operator()
of that temporary passing it sd.isbn()
.
It would be the same as
std::hash<std::string> temp; return temp(sd.isbn());
For more reading on using objects that have a operator()
see: C++ Functors - and their uses
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With