This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Intrinsics for N2965: Type traits and base classes
- From: Michael Spertus <mike_spertus at symantec dot com>
- To: Benjamin Kosnik <bkoz at redhat dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>, "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 27 Sep 2011 20:22:57 -0700
- Subject: Re: Intrinsics for N2965: Type traits and base classes
- References: <20110913154324.4be22faf@shotwell> <4E809F45.2010908@symantec.com> <20110927195930.54e0d0df@shotwell>
Benjamin,
I think tuple is wrong both for performance reasons (I believe these are likely to be serious enough to depress use due to inordinately long compiles) and because it prematurely locks us into a rigid choice of how our typelists are implemented.
My inclination is to make it type-independent by returning an unspecified type that can have a sequence of types extracted from it (this is the approach taken by boost::mpl and has loads of experience that shows it is a good approach to metaprogramming). In other words, first<bases<A>>::type would be the first base of A, etc.
I've coded this up, and it seems to work very well without committing us to any particular typelist implementation. I don't think it has any downsides relative to tuple. I'll do a little benchmarking to compare it to tuple (I suspect it will be far faster) and then send to the library list,
Mike
Sent from my iPhone
On Sep 27, 2011, at 9:59 PM, "Benjamin Kosnik" <bkoz@redhat.com> wrote:
>
>> This patch consists intrinsics to properly create the bases and
>> direct_bases of a class in the correct order (including multiple
>> nested ambiguous virtual and non-virtual classes) for N2965
>> (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2965.html).
>> This allows you to create type traits for giving the base classes of
>> the class:
>>
>> template<typename _Tp>
>> struct bases
>> {
>> typedef tuple<__bases(_Tp)...> type;
>> };
>
> Cool! So glad to see this.
>
>> I didn't modify the standard library to include the above type trait
>> in the patch because it is not yet clear what type it should return
>> (e.g., a tuple, a "typelist," something satisfying the requirements
>> of a boost::mpl sequence, or a generalization of parameter packs). I
>> have (cursorily) tested it with the above type trait and the
>> corresponding direct_bases trait.
>
> OK.
>
> Here's a patch for the above. What's wrong with tuple? I kind of like
> it.... seems simple. It's what's in N2965, so let's start there.
>
> Since it's the first TR2 header, I did the build bits for you.
>
> Also, I cc'd the library list.
>
> best,
> benjamin
> <20110927-4.patch>