Boost logo

Boost :

From: Michael Goldshteyn (mgoldshteyn_at_[hidden])
Date: 2005-03-23 16:37:34


"Jody Hagins" <jody-boost-011304_at_[hidden]> wrote in message
news:20050323104956.15cd7630.jody-boost-011304_at_atdesk.com...
> On Wed, 23 Mar 2005 09:01:51 -0600
> "Michael Goldshteyn" <mgoldshteyn_at_[hidden]> wrote:
>
>> There is a bug in the sample code which cause me a lot of grief in
>> understanding how boost::any functions, this morning. At:
>>
>> http://www.boost.org/doc/html/any/s02.html
>>
>> The code:
>> ---
>> bool is_string(const boost::any & operand)
>> {
>> return any_cast<std::string>(&operand);
>> }
>>
>> should read:
>>
>> bool is_string(const boost::any & operand)
>> {
>> return any_cast<std::string *>(&operand);
>> }
>> ---
>>
>> Notice the addition of the asterisk.
>
>
>
> The original example looks fine to me. Why do you think it is
> incorrect?

The original example casts from an any pointer to an std::string, using
any_cast, and returns the result implicitly cast to a boolean. So:

1. What does it mean to cast from an any pointer to an std::string, using
any_cast?
2. What does it mean to implicitly convert a string, the value returned from
any_cast<string> to a boolean?


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