Boost logo

Boost Users :

Subject: Re: [Boost-users] [Lambda] Misplaced "const" causes runtime error?
From: Igor R (boost.lists_at_[hidden])
Date: 2009-02-16 11:06:09


>
> int main()
> {
> std::vector<std::pair<int, int> > 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<int, int>::first));
> std::transform(pairs.begin(), pairs.end(), std::back_inserter(result),
> boost::bind(&std::pair<int, int>::first, _1));
> std::transform(pairs.begin(), pairs.end(), std::back_inserter(result),
> boost::lambda::bind(&std::pair<int, int>::first, boost::lambda::_1));
> std::cout << result[0] << ' ' << result[1] << ' ' << result[2];
> }
>
> Changing "std::pair<int, int>" to "std::pair<const int, int>" 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.
>

Seems like I saw this somewhere :)
http://www.nabble.com/-boost-users--lambda--crash-in-std::for_each-td21806650.html



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net