Boost logo

Boost :

Subject: Re: [boost] safe-bool CRTP class
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-05-28 17:41:05

On Sat, May 28, 2011 at 1:31 PM, Matt Calabrese <rivorus_at_[hidden]> wrote:

> On Sat, May 28, 2011 at 3:23 PM, Jeffrey Lee Hellrung, Jr. <
> jeffrey.hellrung_at_[hidden]> wrote:
> >
> > Here's a trial attempt at an implementation of the macro (warning: not
> > tested):
> I haven't looked at the implementation in depth, but if I recall correctly,
> C++0x explicit conversions to bool are not quite the same as a safe-bool
> conversion (explicit conversions still generally require explicit casts,
> correct me if I'm wrong). Because of this, I do not believe it would be a
> good idea for such a macro to automatically use explicit conversion
> operators when available as it could result in user code that compiles in
> 03
> but fails to compile in 0x.

You make a good point, and if all C++0x compilers generate equally efficient
code for each technique, then we should just stick with the
slightly-more-complicated pointer-to-member hack.

Perhaps it would prudent to provide a macro flag which signals to use
explicit bool conversion operators when available, for (the rare?) cases
when the compiler generates more efficient code for the explicit bool
conversion operator, and users desire such efficiency.

- Jeff

Boost list run by bdawes at, gregod at, cpdaniel at, john at