简体   繁体   English

使用带有复合表达式的boost lambda

[英]using boost lambda with compound expressions

I have a Visual Studio 2008 C++03 application where I would like to use boost::lambda to perform this action: 我有一个Visual Studio 2008 C ++ 03应用程序,我想使用boost :: lambda来执行此操作:

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? 让boost :: lambda执行复合表达式的正确方法是什么? Do I need to bind the != operator? 我需要绑定!=运算符吗?

Thanks 谢谢

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. 话虽这么说,在新代码中停止使用Boost.Lambda - 它已经被正式弃用(除了文档以外),支持Boost.Phoenix近一年了,而且有充分的理由。 (And your code compiles cleanly as-is when using Phoenix rather than Lambda.) (当你使用Phoenix而不是Lambda时,你的代码就会干净利落地编译。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM