Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-19 07:00:10


On Sat, 18 Jan 2003 21:55:59 -0500, David Abrahams
<dave_at_[hidden]> wrote:

>Gennaro Prota <gennaro_prota_at_[hidden]> writes:

>> I see. Can we expect an "extension" for C++0x then?
>
>Not unless someone makes a formal proposal. Are you volunteering?

Yes, I would be glad to write a formal proposal. But, as it has been
repeatedly pointed out on comp.std.c++, this is not enough if you are
not in the committee and that, de facto, there are very little chances
for the proposal to be approved if you are not present to defend it
and respond to questions and, above all, objections.

>> As I hinted at in a previous post, the limitations about integral
>> constant expressions are a little odd to me. For instance, why
>> prohibiting the comma operator?
>
>I don't know; maybe because there's some implication about order of
>evaluation? Did you check D&E?

I don't have D&E. However this is a legacy of C. The C99 rationale
says:

   "An integer constant expression must involve only numbers
    knowable at translation time, and operators with no side
    effects."

C++ could have IMHO lifted this restriction, to allow at least the
classical sizeof usages in combination with overload resolution as the
EXPLICIT_CAST example shows.

>> Do you remember my EXPLICIT_CAST?
>
>Nope.
>
>> #define EXPLICIT_CAST(dst_type, expr) \
>> ( static_cast< check_helper<dst_type, \
>> sizeof(implicit_cast<dst_type>(expr)) > \
>> :: type>(expr) )
>>
>> The intent was for it to be suitable for constant expressions. Well,
>> as you may have noticed the check_helper<> template was there just
>> because I couldn't do something like:
>>
>>
>> template <typename T>
>> void implicit_cast (typename identity<T>::type x) {
>> return x;
>> }
>>
>>
>> template <typename T>
>> char implicit_cast (...);
>>
>> #define EXPLICIT_CAST(dst_type, expr) \
>> ( sizeof( implicit_cast<dst_type>(expr) ) \
>> , \
>> static_cast<dst_type>(expr) \
>> )
>>
>>
>> This seems natural: you use sizeof to check whether implicit
>> conversion happens, then you discard its result. What's wrong with
>> it?
>
>For one thing, it doesn't check whether an implicit conversion
>occurs.

Uh? It checks whether expr is implicitly convertible to dst_type, in
the sense that if it is then it gives a diagnostic. What do you mean??

>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? The implementation I gave earlier, i.e.

   http://lists.boost.org/MailArchives/boost/msg39819.php

does the same thing.

Genny.


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