Problem updating code to boost 1.64
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
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_caststd::wstring(CurrentAction[0]).compare(...)) If you want it to ignore other types, you'd need something more like: auto actionString = any_caststd::wstring(&CurrentAction[0]); if (actionString && actionString->compare(...))
participants (2)
-
Gavin Lambert
-
Tim Burgess