Question on boost lambda

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • anton.bredikhin@gmail.com

    Question on boost lambda

    Hello everybody.

    I want to write an unnamed predicate for std::find_if in-place.
    If the vector is filled by raw struct, then I can find the target
    element like that:


    struct C
    {
    int i;
    float f;
    }

    int main()
    {
    std::vector<Cv;
    // somehow init v

    std::find_if(v. begin(), v.end(), &_1->*&C::i == 3);
    }


    But I cannot make that to work if vector contains boost::shared_p tr to
    the C struct.
    std::vector<boo st::shared_ptr< C v;
    // somehow init v

    std::find_if(v. begin(), v.end(), ???);

    Can anyone tell me how can I achieve that?

    Thanks
    std::find_if(v. begin(), v.end(), /*v->i==3*/ ??)

    If the vector is filled by structs without shared_ptr, then I can find
    an element like that:

    std::find_if(v. begin(), v.end(), &_1->*&C::i == 3);

    But I cannot make that code to work with pointers.

    Thanks
  • Kai-Uwe Bux

    #2
    Re: Question on boost lambda

    anton.bredikhin @gmail.com wrote:
    Hello everybody.
    >
    I want to write an unnamed predicate for std::find_if in-place.
    If the vector is filled by raw struct, then I can find the target
    element like that:
    >
    >
    struct C
    {
    int i;
    float f;
    }
    >
    int main()
    {
    std::vector<Cv;
    // somehow init v
    >
    std::find_if(v. begin(), v.end(), &_1->*&C::i == 3);
    }
    >
    >
    But I cannot make that to work if vector contains boost::shared_p tr to
    the C struct.
    std::vector<boo st::shared_ptr< C v;
    // somehow init v
    >
    std::find_if(v. begin(), v.end(), ???);
    [snip]

    Try: &*_1->*&C::i == 3


    Best

    Kai-Uwe Bux

    Comment

    • anton.bredikhin@gmail.com

      #3
      Re: Question on boost lambda

      Try:  &*_1->*&C::i == 3
      >
      Best
      >
      Kai-Uwe Bux
      It works!
      Thanks a lot!

      Comment

      Working...