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 mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto

Reply via email to