
On May 25, 2006, at 10:38 AM, Maarten Kronenburg wrote:
"Paul A Bristow" <pbristow@hetp.u-net.com> wrote in message news:E1FjC7o-0000md-FX@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