boost lambda question

Discussion in 'C++' started by nandor.sieben@gmail.com, Mar 11, 2008.

  1. Guest

    Let m be of type vector<vector<int> >. I am trying to sort each
    element of m:

    for_each(m.begin(), m.end(), bind(sort, *_1.begin(), *_1.end());

    This does not work:

    'const struct
    boost::lambda::lambda_functor<boost::lambda::placeholder<1> >' has no
    member named 'begin'

    'const struct
    boost::lambda::lambda_functor<boost::lambda::placeholder<1> >' has no
    member named 'end'

    What do I do wrong?
     
    , Mar 11, 2008
    #1
    1. Advertising

  2. Guest

    On Mar 11, 1:42 pm, wrote:
    > Let m be of type vector<vector<int> >. I am trying to sort each
    > element of m:
    >
    > for_each(m.begin(), m.end(), bind(sort, *_1.begin(), *_1.end());
    >
    > This does not work:
    >


    Boost.Lambda does its magic by overloading operators. However, the
    "dot" operator cannot be overloaded:
    http://www.boost.org/doc/html/lambda/le_in_details.html#lambda.operator_expressions
    So, to create a lambda invoking a member function, you have to use
    bind expressions:
    http://www.boost.org/doc/html/lambda/le_in_details.html#lambda.bind_expressions
    Which makes the expression less elegant : What you want to express as:
    _1.begin()
    becomes something like:
    bind(&std::vector<int>::begin, _1)

    HTH,
    √Čric Malenfant
     
    , Mar 11, 2008
    #2
    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. Roman Suzi
    Replies:
    13
    Views:
    608
    Bengt Richter
    Jan 7, 2005
  2. Toby Bradshaw
    Replies:
    6
    Views:
    1,757
    Kai-Uwe Bux
    Jun 2, 2006
  3. Misiu
    Replies:
    3
    Views:
    2,390
    Misiu
    Jan 31, 2007
  4. Replies:
    0
    Views:
    593
  5. Steve Dogers

    lambda vs non-lambda proc

    Steve Dogers, Mar 30, 2009, in forum: Ruby
    Replies:
    1
    Views:
    178
    Sean O'Halpin
    Mar 30, 2009
Loading...

Share This Page