0

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

PaulH
  • 7,759
  • 8
  • 66
  • 143

1 Answers1

2

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

ildjarn
  • 62,044
  • 9
  • 127
  • 211
  • 1
    What does "officially deprecated in all but documentation" mean? Does it mean that they've deprecated it, without bothering to mention in its own documentation that it's deprecated, so you only hear about it by word of mouth and the Boost mailing lists? If so, that seems to me exactly what *unofficial* deprecation would look like ;-) – Steve Jessop Jun 01 '12 at 01:16
  • 1
    @Steve : You have it right, but it's only because no one has been able to contact Jaakko to update the docs. Jaakko agreed a long time back that as soon as Phoenix was released as a standalone library that it would supersede Lambda, so all Boost authors, even Jaakko, agree that it's deprecated – it's merely a documentation bug at this point. – ildjarn Jun 01 '12 at 01:30
  • 1
    Heh, that's a pretty good SFANU. Something so abandoned that you can't even fix the docs to say it's abandoned! – Steve Jessop Jun 01 '12 at 08:56
  • @ildjarn - Thanks, I didn't know that about boost::lambda. Since boost::phoenix also has a `bind`, is boost::bind also deprecated? – PaulH Jun 01 '12 at 13:51
  • 1
    @PaulH : There's actually ongoing discussion about that on the Boost dev mailing list right now – no definitive verdict yet, but it looks likely in the 1.52ish timeframe. :-] – ildjarn Jun 01 '12 at 16:05