using boost lambda with compound expressions

雨燕双飞 提交于 2019-12-11 17:39:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!