Boost logo

Boost Users :

Subject: Re: [Boost-users] Problem updating code to boost 1.64
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2017-09-26 01:08:44


On 22/09/2017 03:36, Tim Burgess wrote:
> I have an application that I’m resurrecting. I originally coded it using
> Visual Studio 2010 with the boost that was current at the time (not sure
> what version that was). The following line of code used to build fine:
>
>                 if (CurrentAction[ 0].As <std::wstring>().compare(
> wstrFunctionName) == 0)
>
> With my current boost 1.64, I get the following error:
>
> >c:\users\tim\projects\surfacereader\screenreaderfunctionsdlg.cpp(146):
> error C2039: 'As': is not a member of 'boost::any'
>
> The intent of the code is as follows:
>
> If CurrentAction[ 0] (which is a boost::any) contains an std::wstring
> value, compare it to wstrFunctionName.

I don't think that's ever been a supported method of Boost.Any --
perhaps you were using a customised version, or some other Any
implementation?

But the way to extract values from a boost::any is by using any_cast.
If you want it to throw if the action doesn't contain a wstring:

     if (any_cast<std::wstring>(CurrentAction[0]).compare(...))

If you want it to ignore other types, you'd need something more like:

     auto actionString = any_cast<std::wstring>(&CurrentAction[0]);
     if (actionString && actionString->compare(...))


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