Boost logo

Boost Users :

Subject: [Boost-users] [lambda] Lambda bind and upgrading
From: Swerts, Benjamin (Benjamin.Swerts_at_[hidden])
Date: 2011-04-04 11:26:05

Hello all,

In the process of upgrading Boost from 1.39.0 to 1.46.1 I encountered a
few problems with Boost.Lambda. Some places where I used bind and
operator== are not compiling anymore with Visual Studio 2008 SP1. Here's
a self-contained example showing the problem:

#include <algorithm>
#include <vector>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
using boost::lambda::bind;
using boost::lambda::_1;

struct A { unsigned int id; };
struct B { const A* a; };

int main()
  const std::vector<B> vb;
  std::find_if(vb.begin(), vb.end(), bind(&A::id, bind(&B::a, _1)) ==
  return 0;

- This code compiles fine with Boost 1.39.0
- When compiled with Boost 1.46.1 it shows the following error:

  boost_1_46_1/boost/lambda/detail/function_adaptors.hpp(280) : error
C2440: 'return' : cannot convert from 'const unsigned int' to 'unsigned
int &'

- When removing the 'const' before the vector, this doesn't even compile
in 1.39.0
- What's even stranger is that a simpler version doesn't compile under
other circumstances. This compiles with 1.46.1:

  std::vector<A> va;
  std::find_if(va.begin(), va.end(), bind(&A::id, _1) == 2);

  but making the vector const doesn't (exact same error message). Both
compile fine with 1.39.0.

Both examples compile fine when I use Boost.Bind but that's not always a
possible backup plan. I do plan on replacing all the bind calls with
their Phoenix v3 equivalents but I first need to get Boost upgraded.

Many thanks in advance for any insights.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at