This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Use conditional casting with symtab_node


On 9/19/12, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
> On Sep 19, 2012 Richard Guenther <richard.guenther@gmail.com> wrote:
> > Indeed.  Btw, can we not provide a specialization for
> > dynamic_cast <>?  This ->try_... looks awkward to me compared
> > to the more familiar
> >
> > vnode = dynamic_cast <varpool_node> (node)
> >
> > but yeah - dynamic_cast is not a template ... (but maybe there
> > is some standard library piece that mimics it?).
>
> No, it is a language primitive.
>
> but we can define out own operation with similar syntax that allows
> for specialization, whose generic implementation uses dynamic_cast.
>
>   template<typename T, typename U>
>   T* is(U* u) {
>       return dynamic_cast<T*>(u);
>   }

At this point, dynamic_cast is not available because we do not
yet have polymorphic types.  There has been some resistance to
that notion.

Absent dynamic cast, we need to specialize for various type
combinations.  Function template specialization would be handy,
but C++ does not directly support that.  We could work around
that.  However, in the end, the fact that try_whatever is a member
function means that we can use a notation that depends on context
and so can be shorter.  That is, we can write 'function' instead of
'cgraph_node *'.

-- 
Lawrence Crowl


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]