STL list using find_if lookup algorithm

Source: Internet
Author: User


Set and Multiset map and Multimap have member functions find function to quickly locate


Vector and list no find functions want to find traversal through iterators


The following uses the class overloading operator to implement FIND_IF quick lookups:


typedef struct STRTMPLINKMAN

{

CString Tmplinkmanname;

CString Tmplinkmaneemail;

}strtmplinkman;

typedef std::list<strtmplinkman> TMPLINKMAN_T;

typedef std::list<strtmplinkman>::iterator tmplinkmaniter_t;


Class Findthevalstring

{

Does the STL find Tmplinkmanemail contain

Public

Findthevalstring (CString str): M_linkmanemail (str) {};

BOOL Operator () (const Strtmplinkman &t) const

{

return m_linkmanemail = = T.tmplinkmaneemail;

}

Private

CString M_linkmanemail;

};

typedef struct STRTMPGROUP

{

Strtmpgroup ()

{

PList = NULL;

}

CString Strtmpgroupname;

clistuiex* pList;

Tmplinkman_t strtmplinklist;

}strtmpgroup;


typedef std::list<strtmpgroup> STRTMPGROUPLIST_T;

typedef std::list<strtmpgroup>::iterator strtmpgroupiter_t;


Class Findtheval

{

The STL finds whether clistuiex* plist contains

Public

Findtheval (clistuiex* x): M_age (x) {};

BOOL Operator () (const strtmpgroup &t) const

{

return m_age = = T.plist;

}

Private

clistuiex* M_age;

};



typedef struct STGROUPUSER_T

{

stgroupuser_t ()

{

Ptmpgrouplist = NULL;

}

strtmpgrouplist_t* ptmpgrouplist;

}stgroupuser_t;


extern stgroupuser_t G_sttmpgroupinfo;


Std::list<strtmpgroup>::iterator finded_plist = find_if (G_sttmpgroupinfo.ptmpgrouplist->begin (), g_ Sttmpgroupinfo.ptmpgrouplist->end (), Findtheval (prightlist));

if (finded_plist! = G_sttmpgroupinfo.ptmpgrouplist->end ())

{

Found it

Find out if there is the same string linkmanemail

Std::list<strtmplinkman>::iterator finded_string = find_if (Itertmpgroupinfo->strtmplinklist.begin (), Itertmpgroupinfo->strtmplinklist.end (), findthevalstring (Sttmplinkman.tmplinkmaneemail));

if (finded_string = = Itertmpgroupinfo->strtmplinklist.end ())

{

Not found.

}

}

STL list using find_if lookup algorithm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.