From: Jesse Jones (jesjones_at_[hidden])
Date: 2000-11-18 17:12:08
>> >Why is that? A bool conversion says "valid" or "invalid" to call.
>> No, a bool conversion says that I can be implcitly converted to a
>> which can in turn be used used in an arithmetic expression. So,
>> callback<void> c(Foo);
>> int sum = c + 1;
>> compiles just fine. This is a big enough problem that I never use
>> conversion operators.
>I honestly don't see this particular example as being a problem at
>all, let alone a big one. Who cares if the above compiles? It won't
>hurt anything, and it may well be that the programmer intended the
>above to work just in the way that it does. Given only that example
>it seems like we're spending too much effort on safety over
>useability. Is there a more compelling example that shows true
It may be my Modula-2 background, but I prefer to use the type system to
stop nonsense from compiling. And, after all, "if (!callback.empty())
callback()" is very nearly as useable as "if (callback) callback()".
>> >A const void* implies some sort of useful value (which would
>> It doesn't neccesarily imply that you can do anything useful with
>> other than compare it to NULL or another void*.
>Or compare it to any value that can be implicitly converted to void*,
>which includes any other pointer type. So you can compare
>the "callback" with a function pointer with (possibly surprising)
>> However the conversion
>> rules make const void* much more type safe than bool's.
Well maybe much was an over statement. :-) It is pretty safe though. It's
not like you can just treat a callback as a pointer. For example, "int*
p= (int*) callback" won't compile.
>I've yet to see any arguments that convince me of this. The opposite
>was decided for boost::any (though they removed the implicit
>conversion entirely, I believe, which may or may not be appropriate
My recollection is that Kevlin thought a const void* conversion was
better than a bool conversion, but someone pointed out that that allowed
two any objects to be compared with bad results which was enough to shoot
down the conversion operator. Callbacks present exactly the same problem
From my POV I think bool conversions should pretty much never be used and
const void* conversions should only be used where you can provide
comparison operators yourself.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk