PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Question on boost lambda
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Question on boost lambda

Réponse
 
LinkBack Outils de la discussion
Vieux 07/11/2008, 14h57   #1
anton.bredikhin@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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<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
  Réponse avec citation
Vieux 07/11/2008, 15h44   #2
Kai-Uwe Bux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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<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
  Réponse avec citation
Vieux 07/11/2008, 16h18   #3
anton.bredikhin@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Question on boost lambda

> Try: &*_1->*&C::i == 3
>
> Best
>
> Kai-Uwe Bux


It works!
Thanks a lot!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h26.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,23114 seconds with 11 queries