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.
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.
std::hash
is a class type. What you are doing here is constructing a temporarystd::hash
withhash<string>()
and then(sd.isbn())
calls theoperator()
of that temporary passing itsd.isbn()
.It would be the same as
For more reading on using objects that have a
operator()
see: C++ Functors - and their uses