Hi,
The following program, as expected, outputs "1 1 1":
#include <algorithm>
#include <iostream>
#include <vector>
#include
#include
#include
int main()
{
std::vector > pairs;
pairs.push_back(std::make_pair(1, 1));
std::vector<int> result;
std::transform(pairs.begin(), pairs.end(), std::back_inserter(result),
boost::mem_fn(&std::pair::first));
std::transform(pairs.begin(), pairs.end(), std::back_inserter(result),
boost::bind(&std::pair::first, _1));
std::transform(pairs.begin(), pairs.end(), std::back_inserter(result),
boost::lambda::bind(&std::pair::first, boost::lambda::_1));
std::cout << result[0] << ' ' << result[1] << ' ' << result[2];
}
Changing "std::pair" to "std::pair" on the line
using boost::mem_fn or the line using boost::bind causes a compile-time
error.
However, performing the same change on the line using boost::lambda::bind
leads to a successful compile - yet at run-time result[2] is set to a
seemingly random value. This has been tested on Visual C++ 7.1 SP1, 8.0 SP1
and 9.0 SP1.
Is this expected behaviour? I was expecting to see either a compile-time
error or run-time success.
Thanks