Boost logo

Proto :

Subject: Re: [proto] Extendin proto::switch_
From: Eric Niebler (eric_at_[hidden])
Date: 2011-08-06 16:36:04


On 8/6/2011 1:26 PM, Joel falcou wrote:
> On 06/08/11 21:01, Eric Niebler wrote:
>> Besides, enable_if is yuk.
>
> Care to elaborate (not like we use it like over 9000 times in our code
> base) /

I just don't like it. SFINAE is an ugly hack. There may also be
compile-time perf impacts. Consider:

template<class T>
struct foo< T, typename emable_if< X<T> >::type * = 0>

template<class T>
struct foo< T, typename emable_if< Y<T> >::type * = 0>

template<class T>
struct foo< T, typename emable_if< Z<T> >::type * = 0>

Now, imagine that X, Y and Z are all expensive metafunctions. They must
*all* be computed before the compiler can select the correct
specialization. Had we written it as:

template<class T>
struct select { typedef ... type; };

template<class T, class Case = typename select<T>::type>
struct foo;

template<class T>
struct foo<T, x_tag>

template<class T>
struct foo<T, y_tag>

template<class T>
struct foo<T, z_tag>

Then we bring the number of template instantiations from O(N) (in the
number of cases) down to O(1) (assuming that select is O(1)).

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Proto list run by eric at boostpro.com