使用boost拉姆达与复合前pressions [英] using boost lambda with compound expressions

查看:222
本文介绍了使用boost拉姆达与复合前pressions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio 2008的C ++ 03应用程序,我想使用boost :: lambda来执行此操作:

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 );

什么是获得的boost :: lambda来进行复合前pressions正确的方法是什么?我需要绑定!=运算符?

What's the correct way to get boost::lambda to perform compound expressions? Do I need to bind the != operator?

感谢

推荐答案

我不知道潜在的问题是什么,但加入了铸使得它的工作:

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);

话虽这么说,停止新的code&ndash的使用Boost.Lambda;它一直赞成pcated(在所有文件) Boost.Phoenix 正式去$ P $近一年了,有很好的理由。 (和AS-使用时,凤凰城,而不是你的lambda code编译干净。)

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.)

这篇关于使用boost拉姆达与复合前pressions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆