Boost logo

Boost :

Subject: Re: [boost] safe-bool CRTP class
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2011-05-29 08:07:22

On 28.05.2011, at 22:31, Matt Calabrese 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).

True. You can only omit the case in "contextual conversion" situations, which are:
- Conditions of if, while, do..while and for (maybe switch? not sure).
- Arguments to &&, || and !.
- First argument to ?:.

So these two code examples that a 03 user might write would fail:

convertible_to_bool obj;
bool b = obj; // must write bool b(obj);

void fn(bool);
fn(obj); // must cast


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