boost::lambda::bind

Discussion in 'C++' started by Barry Ding, Jul 22, 2007.

  1. Barry Ding

    Barry Ding Guest

    #include <boost/lambda/lambda.hpp>
    #include <boost/lambda/bind.hpp>

    using namespace std;
    using namespace boost::lambda;

    struct A {
    A(int i) : i(i) {}
    void print() const {
    cout << "A::print: " << i << endl;
    }
    int i;
    };

    int main()
    {
    list<A> List;
    List.push_back(A(1));
    List.push_back(A(2));
    List.push_back(A(3));
    List.push_back(A(4));
    for_each(List.begin(), List.end(), cout << bind(&A::i, _1) << '
    '); // works

    map<char const*, int> Map;
    Map["hello"] = 10;
    Map["world"] = 11;
    for_each(Map.begin(), Map.end(),
    cout << bind(&(pair<char const*, int>::first), _1)
    //illegal reference to non-static member
    //'std::pair<_Ty1,_Ty2>::first'
    << ' '
    << bind(&(pair<char const*, int>::second), _1)
    );

    return 0;
    }
    Barry Ding, Jul 22, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Toby Bradshaw
    Replies:
    6
    Views:
    1,727
    Kai-Uwe Bux
    Jun 2, 2006
  2. Misiu
    Replies:
    3
    Views:
    2,354
    Misiu
    Jan 31, 2007
  3. Replies:
    4
    Views:
    411
  4. Replies:
    0
    Views:
    581
  5. Christopher
    Replies:
    1
    Views:
    793
    Yakov Gerlovin
    Oct 5, 2011
Loading...

Share This Page