Boost logo

Boost :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2006-05-25 10:44:05


On May 25, 2006, at 10:38 AM, Maarten Kronenburg wrote:
> "Paul A Bristow" <pbristow_at_[hidden]> wrote in message
> news:E1FjC7o-0000md-FX_at_he303war.uk.vianw.net...
>>
>> 2 If you have to write is_zero() instead of == 0, will this make
> templated
>> code difficult?
>
> The == 0 notation is always allowed, also in templates,
> but it is a little slower than is_zero().
> The == 0 generates a temporary integer with value zero,
> by implicit converting constructor.
> But in templates that also should work for template type
> parameter int, the == 0 indeed must be used.

You can actually make "== 0" work without generating the temporary
integer. Search for "clear_type" and "enable_if" in the
Boost.Function source code to see the trick. Basically, it relies on
some SFINAE and the fact that "0" is convertible to a pointer...

        Doug


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