This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: compile-time cost of alias templates
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Dodji Seketeli <dodji at redhat dot com>, Jason Merrill <jason at redhat dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Sun, 18 Dec 2011 17:30:30 +0000
- Subject: Re: compile-time cost of alias templates
- References: <CAH6eHdTmidJTXCBDCMXudyDrV9TrnK+awD-J5hrssQjKLPk52A@mail.gmail.com>
On 18 December 2011 16:00, Jonathan Wakely wrote:
> I don't know the G++ internals well enough to find this out for
> myself, so I hope Dodji or Jason can answer the question below.
>
> Currently in <functional> we have this helper class to constrain the
> std::bind function template via SFINAE:
>
> ?template<typename _Tp>
> ? ?class __is_socketlike
> ? ?{
> ? ? ?typedef typename decay<_Tp>::type _Tp2;
> ? ?public:
> ? ? ?static const bool value =
> ? ? ? ?is_integral<_Tp2>::value || is_enum<_Tp2>::value;
> ? ?};
>
> I was going to replace the static member with:
> ? ? ?static const bool value = __or_<is_integral<_Tp2>, is_enum<_Tp2>>::value;
>
> But now that we have alias templates I'm wondering if it would be
> better to write it as:
>
> ?template<typename _Tp>
> ? ?using __is_socketlike
> ? ? ?= __or_<is_integral<typename decay<_Tp>::type>,
> ? ? ? ? ? ? ?is_enum<typename decay<_Tp>::type>>;
Or slightly shorter:
template<typename _Tp, typename _Tp2 = typename decay<_Tp>::type>
using __is_socketlike = __or_<is_integral<_Tp2>, is_enum<_Tp2>>;
> Does the implementation in G++ mean that using an alias template
> avoids instantiating the separate __is_socketlike class template, or
> is there just as much cost in instantiating an alias template as a
> class template?
I found that when __is_socketlike is an alias instead of a class
template it avoids a call to instantiate_class_template_1 in cp/pt.c,
but I don't know if there's something else being done for the alias
which is equally (or more?) expensive.