|
Boost : |
From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-18 14:52:57
On Sat, 18 Jan 2003 14:14:37 -0500, David Abrahams
<dave_at_[hidden]> wrote:
>Gennaro Prota <gennaro_prota_at_[hidden]> writes:
>
>> On Sat, 18 Jan 2003 13:13:45 -0500, David Abrahams
>> <dave_at_[hidden]> wrote:
>>
>>>Gennaro Prota <gennaro_prota_at_[hidden]> writes:
>>>> Unfortunately
>>>> the committee seems on the road of prohibiting this and other similar
>>>> (and potentially more useful) uses of string literals in constant
>>>> expressions:
>>>>
>>>> http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#366
>>>
>>>Huh? They're already prohibited.
>>
>> I meant that they (you ;-)) want to prohibit any use of string
>> literals in constant expressions.
>
>Nobody "wants to".
Ah ok. Everybody has always been wanting to ;-)
>It's not well-defined in the standard what it means to treat a string
>literal as an integral constant expression. Nobody ever intended them
>to be integral constant expressions.
Here we go.
>In standardization, you don't
>resolve problems like this by exploiting loopholes, and especially
>during this stage of standardization, which is dedicated to closing
>them. If you want to enable a new capability, you deal with it
>separately and intentionally.
I see. Can we expect an "extension" for C++0x then?
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? Do you remember my EXPLICIT_CAST?
#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?
Why prohibiting such a usage in a constant expression?
Genny.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk