Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::any with const value types
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2016-07-07 17:24:06


AMDG

On 07/05/2016 12:31 PM, Robert Dailey wrote:
> I'm finding that if I store a `char*` versus `char const*` in a
> boost::any object, that this impacts the behavior of boost::any_cast.
> I do not find this documented anywhere.
>
> For example, if I store a const qualified character pointer in a
> boost::any object, then I do `boost::any_cast<char*>(......)`, it will
> throw. Changing the type to `char const*` fixes it.
>
> Is this by design? I find this makes things more difficult to deal
> with since I don't always know if the type I'm getting is const or
> not. Also my implementation does not change depending on constness.
>

  Yes, this is by design. The rule is that
you can only get out the same type that you
put in. char * is not the same type as
char const *.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net