Boost logo

Boost Users :

From: Fei Liu (fei.liu_at_[hidden])
Date: 2007-09-25 10:38:12


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 <boost/lambda/lambda.hpp>
#include <boost/ref.hpp>
#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';
}


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