|
Boost : |
Subject: Re: [boost] "Simple C++11 metaprogramming"
From: Agustín K-ballo Bergé (kaballo86_at_[hidden])
Date: 2015-07-16 17:01:27
On 7/16/2015 5:29 PM, Mathias Gaunard wrote:
> On 16/07/15 12:12, Peter Dimov wrote:
>> Mathias Gaunard wrote:
>>> A core foundational library should not instantiate templates that it
>>> doesn't strictly need to.
>>> Instantiating templates has a very high impact on compile-time memory
>>> usage, performance, ...
>>
>> That's not always true in C++11/17. One example is the and<T...>
>> primitive, for which the short-circuit version is much slower than the
>> one that always expands T::value...
>
> That would depend on the cost of instantiating T, which you cannot
> predict since it is a user-defined type.
There's merit for both approaches, as it depends entirely on the use
case. For instance, when used in a `static_assert` the possible benefits
of short-circuiting the `false` case is irrelevant, while a cheaper
`true` case is beneficial.
Given that the eager version is straightforward to write in C++17, it'd
be preferable for `and_` to represent the traditional short-circuited
approach its name implies.
Regards,
-- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk