Boost logo

Boost :

Subject: Re: [boost] Is there BOOST_ENABLE_IF macro now?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2013-08-19 10:38:24


On 18/08/13 21:41, Matt Calabrese wrote:

> Mathias, do you have any reason for the assertion that it's "unnecessarily
> inefficient" at compile time?

- It instantiates more templates (at least 4 instead of 1, and much
worse if going through the function_traits path)
- It increases symbol size.
- It requires an additional name resolution and overload resolution step.

> Please post a comparison of compile-times and
> I'll optimize if necessary. Otherwise, for now I'd say just use the macros
> when you can and use std::enable_if or boost::enable_if if you have to.
> I've pretty much just used the macros for the past year or so.

You just can't beat the efficiency of a single instantiation of a
trivial class template like enable_if_c.

Really I don't see how all that cost and portability concerns make it
worthwhile to write

template<class T, BOOST_ENABLE_IF(is_same<T, float>))
int f(T const&)
{
   return 0;
}

instead of

template<class T>
typename enable_if< is_same<T, float>
                   , int
>::type
f(T const&)
{
   return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk