From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24857 invoked by alias); 19 Sep 2012 21:15:14 -0000 Received: (qmail 24778 invoked by uid 22791); 19 Sep 2012 21:15:11 -0000 X-SWARE-Spam-Status: No, hits=-5.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-vc0-f175.google.com (HELO mail-vc0-f175.google.com) (209.85.220.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 19 Sep 2012 21:14:57 +0000 Received: by vcqp1 with SMTP id p1so2049236vcq.20 for ; Wed, 19 Sep 2012 14:14:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.70.15 with SMTP id i15mr2152024vdu.100.1348089296739; Wed, 19 Sep 2012 14:14:56 -0700 (PDT) Received: by 10.220.54.200 with HTTP; Wed, 19 Sep 2012 14:14:56 -0700 (PDT) In-Reply-To: References: <1375463.iT5QZqtEjJ@polaris> <3934395.Nvssfvq8AW@polaris> Date: Wed, 19 Sep 2012 21:28:00 -0000 Message-ID: Subject: Re: Use conditional casting with symtab_node From: Gabriel Dos Reis To: Lawrence Crowl Cc: Richard Guenther , Eric Botcazou , gcc-patches@gcc.gnu.org, Jan Hubicka , Diego Novillo Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-09/txt/msg01408.txt.bz2 On Wed, Sep 19, 2012 at 1:39 PM, Lawrence Crowl wrote: > On 9/19/12, Gabriel Dos Reis wrote: >> On Sep 19, 2012 Richard Guenther 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 (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 >> T* is(U* u) { >> return dynamic_cast(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. Hmm, when did we rule that out? We currently implement dynamic_cast using the poor man's simulation based on tree_code checking. We can just as well give such simulation the is<> notation. > 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. We can always use the standard workaround: call a static member function of a class template that can be specialized at will. > 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