|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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<C> v; // 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_ptr to the C struct. std::vector<boost::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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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<C> v; > // 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_ptr to > the C struct. > std::vector<boost::shared_ptr<C> > v; > // somehow init v > > std::find_if(v.begin(), v.end(), ???); [snip] Try: &*_1->*&C::i == 3 Best Kai-Uwe Bux |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
> Try: &*_1->*&C::i == 3
> > Best > > Kai-Uwe Bux It works! Thanks a lot! |
|
![]() |
| Outils de la discussion | |
|
|