Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-01-19 12:59:16


Gennaro Prota <gennaro_prota_at_[hidden]> writes:

> On Sun, 19 Jan 2003 09:42:51 -0500, David Abrahams
> <dave_at_[hidden]> wrote:
>
>>>>For another thing, it would be a compile-error if the
>>>>expression *can* be implicitly converted to the destination type,
>>>>which makes no sense to me.
>>>
>>> Isn't this the intent?
>>
>>I don't know what the intent is; you never explained that to me. What
>>this does is to static_cast only when it must be forced (often in the
>>"unsafe" direction); it was hard to see how that could be useful.
>>Maybe just as a way of stating and checking that you know what you're
>>doing?
>
> Well, actually I did it just for the fun of it. The original thread
> was about implicit_cast, not explicit, and I added some thoughts. In
> any case the comment I've made here about the comma operator applies
> to the implicit piece as well:
>
> template <typename T>
> char implicit_cast (typename identity<T>::type x) {
> return x;
> }
>
> // incomplete return type now is here
> template <typename T>
> void implicit_cast (...);
>
> #define IMPLICIT_CAST(dst_type, expr) \
> ( sizeof( implicit_cast<dst_type>(expr) ) \
> , \
> static_cast<dst_type>(expr) \
> )

Why wouldn't you just write implicit_cast<dst_type>(expr) in this
case? Are you trying to save copies?

(You might think I'm not interested in the comma operator issue. I
guess you'd be right. It would be good to do something about it, but
I don't feel strongly. If you do, you will have to champion it).

-- 
                       David Abrahams
   dave_at_[hidden] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

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