Forgive my ignorance, I ran into this "little" function coming from LLVM source base about so called "enhanced RTTI", still couldn't figure out what does it mean.
> especially, at line 3, how come there is another template-like thing.
This is a partial specialization of a base template.
There has to be a base template isa_impl_cl somewhere higher up in the code, along the lines of
template <class T> struct isa_impl_cl { ...
};
Imagine the base template as a generic version of what isa_impl_cl should look like for most types T.
Now isa_impl_cl seems to have to be something different if it is instantiated on a reference type. That's where the code you posted comes in. If isa_impl_cl is instantiated on a reference type, the compiler will use this more specialized version.
yuanfang wrote: > Forgive my ignorance, I ran into this "little" function coming from > LLVM source base about so called "enhanced RTTI", still couldn't > figure out what does it mean.
> Forgive my ignorance, I ran into this "little" function coming from > LLVM source base about so called "enhanced RTTI", still couldn't > figure out what does it mean.
> especially, at line 3, how come there is another template-like thing. > Thank you guys who is willing to reply.
This function simply calls another version of this function that gets a pointer instead of a reference. The thing in line 3 is a partial specialization of the struct for templates only.
yuanfang wrote: > Forgive my ignorance, I ran into this "little" function coming from > LLVM source base about so called "enhanced RTTI", still couldn't > figure out what does it mean.
> especially, at line 3, how come there is another template-like thing. > Thank you guys who is willing to reply.
That's a partial specialization. There should already have been a declaration (and probably a definition, called the "primary template") template<class FromCl> struct isa_impl_cl. In the code you posted, the author has effectively told the compiler "when you instantiate the isa_impl_cl template, if the template argument is a reference type, use this special definition instead of the original." In the body, the "isa" member function template just delegates to a similarly named member function template in the primary template definition. The point apparently is that the original "isa" accepts a pointer, whereas this specialization accepts a reference (and just passes the address of the referenced object down to the original definition),