Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2004-05-23 02:53:09


On Sat, 22 May 2004 13:11:39 -0400, David Abrahams
<dave_at_[hidden]> wrote:

>Gennaro Prota <gennaro_prota_at_[hidden]> writes:
>
>> On Sun, 16 May 2004 10:40:52 -0400, David Abrahams
>> <dave_at_[hidden]> wrote:
>>
>>>So, should I just remove it?
>>
>> Well, not because it isn't implementable.
>
>Sorry, I can't parse that. Should I remove it or not? Is it
>implementable?

It's my English to be quite unparseable ;) Yes, I showed a possible
implementation in the last post:

// Macro for when you need a constant expression.
// Note that 'expr' appears three times but is
// evaluated (at most) once.
#define BOOST_IMPLICIT_CAST(dest_type, expr) \
  (static_cast< dest_type >( \
                 sizeof(boost::implicit_cast< dest_type >(expr)) ? \
                 (expr) : (expr) \
                ) \
  )

As you see, it's a simple

  static_cast < type-id > ( expression )

plus the implicit_cast<> test inside a sizeof. The difference with the
other version (which had the typename problem you point out) is that
sizeof is used inside the *expression* instead of the type-id; thus no
template class is used as a helper and no typename keyword must be
"hard-coded" inside the macro definition.

So: if the only reason why you wanted to remove it was the typename
problem then the macro can remain :) OTOH, I understand you might want
to remove it anyway, as "implicit casts" in constant expressions
aren't the most frequent thing C++ programmers do. It's up to you, I
think. I wrote it mainly for fun.

>
>Maybe your code below answers those questions...

Yes, there was a new implementation and a few examples usages.

>[...]
>
>I like it. Maybe it's time to document this stuff, too ? ;-)

Ok :) Let me know if you want to leave it or not.

Genny.


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