What does this say:
return static_cast<Hasher &>(*this)(key);
?
I can't tell whether *this
or key
is passed to static_cast
. I looked around and found this answer, but unlike what I'm stuck on, there's nothing inside the first pair of parentheses.
If you're unsure, you can just look up the syntax.
In the informal documentation, the only available syntax for
static_cast
is:and the same is true in any standard draft you compare.
So there is no
static_cast<T>(X)(Y)
syntax, and the only possible interpretation is:new-type = Hasher&
expression = *this
and the overall statement is equivalent to
In the skarupke/flat_hash_map code you linked, the interpretation is that this class has a function call operator inherited from the private base class
Hasher
, and it wants to call that explicitly - ie,Hasher::operator()
rather than any other inheritedoperator()
. You'll note the same mechanism is used to explicitly call the other privately-inherited function call operators.It would be more legible if it used a different function name for each of these policy type parameters, but then you couldn't use
std::equal_to
directly for theEqual
parameter, for example.It might also be more legible if it used data members rather than private inheritance for
Hasher
,Equal
etc. but this way is chosen to allow the empty base-class optimization for stateless policies.