Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-09-08 09:11:18


Ed Brey wrote:
> Douglas Gregor wrote:
>
> Unless I missed something bool_testable only provides half the problem: it provides operator!, but not the implicit bool conversion.

I hope you missed something, because bool_testable means that you write
an operator bool() yourself and bool_testable makes it as safe as the
safe-bool-idiom. You have to provide something anyway, so why not the
most obvious operator bool() as this is actually what you are trying to
achive, isn't it? The problem is usually that this is not safe enough,
but bool_testable provides exactly that.

It does so by providing a private operator int() which means that
conversions to bool use your operator bool() as expected (and as
efficient as, well, operator bool()) and all other conversions (to int,
float, ...) are either an access violation (as operator int() is
private) or ambiguous.

I think you should have a closer look at bool_testable and give it
another try. If you have further questions, I hope I can answer them :)

Regards, Daniel

-- 
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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