问题
I have a Visual Studio 2008 C++03 application where I would like to use boost::lambda to perform this action:
enum { fooflag = 0x00000001; }
bool IsFooFlagActive( DWORD flags )
{
return ( flags & fooflag ) != 0;
}
Unfortunately, this doesn't work:
namespace bl = boost::lambda;
bool is_foo_flag_active = ( ( bl::_1 & fooflag ) != 0 )( 0x00000001 );
What's the correct way to get boost::lambda to perform compound expressions? Do I need to bind the != operator?
Thanks
回答1:
I don't know what the underlying issue is, but adding a cast makes it work:
namespace bl = boost::lambda;
bool is_foo_flag_active =
((bl::_1 & static_cast<DWORD>(fooflag)) != 0)(0x00000001);
That being said, stop using Boost.Lambda in new code – it's been officially deprecated (in all but documentation) in favor of Boost.Phoenix for nearly a year now, and with good reason. (And your code compiles cleanly as-is when using Phoenix rather than Lambda.)
来源:https://stackoverflow.com/questions/10841916/using-boost-lambda-with-compound-expressions