Hello, group I am trying out the code snippet in
http://www.boost.org/doc/html/lambda/le_in_details.html 'Naming delayed
constants and variables'. I got some compile errors complaining about
synthesized method error with the following code:
#include <iostream>
#include
#include
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
using namespace boost::lambda;
using namespace boost;
int main(){
int i = 1;
(_1 += 2)(i); // i is now 3
(++_1, cout << _1 << '\n')(i); // i is now 4, outputs 4
int j = 40;
_1 = j;
var(i) = _1 = j;
cout << i << '\n';
vector<int> a;
a.reserve(10);
a.resize(10);
//for_each(a.begin(), a.end(), istream_iterator<int>(cin));
// for_each(a.begin(), a.end(), cin >> _1);
i = 0;
for_each(a.begin(), a.end(), (_1 = var(i)++)); // delayed evaluation
through 'var'
for_each(a.begin(), a.end(), cout << _1 << ' ');
cout << '\n';
for_each(a.begin(), a.end(), cout << ' ' << _1);
cout << '\n';
for_each(a.begin(), a.end(), (var(j) = _1, _1 = var(i), var(i) =
var(j))); <------------ Error
for_each(a.begin(), a.end(), cout << _1 << ' ');
cout << '\n';
}