Boost logo

Boost :

Subject: Re: [boost] �
From: Jeffrey Lee Hellrung, Jr. (jhellrung_at_[hidden])
Date: 2010-08-13 13:28:28


On 8/13/2010 10:03 AM, vicente.botet wrote:
> ----- Original Message -----
> From: "Jeffrey Lee Hellrung, Jr."<jhellrung_at_[hidden]>
> To:<boost_at_[hidden]>
> Sent: Friday, August 13, 2010 6:49 PM
> Subject: Re: [boost] �
>
>> On 8/13/2010 9:16 AM, vicente.botet wrote:
>>> Hi,
>>> ----- Original Message -----
>>> From: "Jeffrey Lee Hellrung, Jr."<jhellrung_at_[hidden]>
>>> To:<boost_at_[hidden]>
>>> Sent: Friday, August 13, 2010 5:35 PM
>>> Subject: Re: [boost] [chrono] v0.4.5 Documentation update + warnings removal + bug fixes
>>>
>>>> Is it necessary for common_type to fallback to Boost.TypeOf in the
>>>> absence of decltype? In what situations is (bool ? T : U) not either T,
>>>> U, or some additional const/volatile qualifications on T or U, possibly
>>>> transposed with some reference or pointer qualifiers?
>>>>
>>>> In other words, when does (bool ? T : U) manufacture some new "3rd type"
>>>> out of the blue?
>>>
>>> (bool ? T : U) is incorrect as the ?: operator don't works on types but on expression. This is exactle the role of typeof. Are I'm missing something?
>>
>> Okay, sorry, my fault for being lazy ;) Replace (bool ? T : U) with (b
>> ? t : u); b of type bool; t of type T; u of type U; and t and u are
>> rvalues unless T and U (respectively) are (lvalue) reference types.
>
> This is exactly what is in the code, other than I use functions instead of variables.

Sure.

>
> static bool m_f(); // workaround gcc bug; not required by std
> static T m_t();
> static U m_u();
> public:
> typedef BOOST_TYPEOF_TPL(m_f() ? m_t() : m_u()) type;
>
> We need however to transform the expression "(b ? t : u)" on a type and I don't see how to achieve it without typeof. Do you?

My question is, if you can enumerate all possible candidates for (b ? t
: u ) in terms of simple (C++03) transformations on T and U, then
there's no need for Boost.TypeOf. You can get by with the "sizeof()
trick", a la a slightly more elaborate boost::is_convertible. This
could make the implementation more complex, but more robust (for C++03),
which I think is an overall win. Do you agree?

So...back to my original question?

I'm definitely not saying with certainty that an implementation that
does not use Boost.TypeOf is possible. I'm just no expert on the
conditional operator, and I'm looking for an instance where (b ? t : u)
can't be determined from applying simple transformations (e.g., removing
reference qualifiers, or adding cv qualifiers) to T and U.

>> Additionally, common_type operates on types, not expressions, so you
>> know the types you're working with in the hypothetical conditional
>> expression.
>
> This is correct, but I don't see how this is related to your concern.

It's not; it was meant to address your comment that "?: operator don't
works on types but on expression", but I think we're on the same page now.

- Jeff


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