Problem updating code to boost 1.64

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem updating code to boost 1.64

Boost - Users mailing list

Hi,

 

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.

 

Can anybody offer some guidance, please?

 

Best wishes.

 

Tim Burgess

 


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Problem updating code to boost 1.64

Boost - Users mailing list
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 mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users