Boost logo

Boost :

Subject: Re: [boost] How to cast _1 ?
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2010-09-28 23:08:19


On Tue, Sep 28, 2010 at 1:06 PM, Henry Tan <henryws_at_[hidden]> wrote:
> I want to cast a value of _1 to a _val of a different type. How do I do
> that? I tried using static_cast_, it does not compile for me.
>
>
> rule<UInt8Iterator, UInt32()> MyRule;
>
> ...
>
> MyRule = (long_ | float_)                                         [_val =
> static_cast_<UInt32>(_1)]
>
> Any help is appreciated

Well considering that (long_ | float_) created a
boost::variant<long,float>, what happens it you cast a
boost::variant<long,float> to UInt32? Compile time error of course.

If you want it 'simple', create a phoenix function
boost::variant<long,float> handle to UInt32.

If you want it to execute the fastest, then create a customization
point in the spirit grammar and do the same thing in it, a bit more
involved, but the fastest execution speed.


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