If you are using C++0X you can use a simple lambda expression
std::string username = "Nicholas";
std::find_if(userlist.begin(), userlist.end(), [username](Nick const& n){
return n.username == username;
})
More Related Contents:
- Using local classes with STL algorithms
- STL algorithms: Why no additional interface for containers (additional to iterator pairs)?
- In which scenario do I use a particular STL container?
- C++ sorting and keeping track of indexes
- What are the complexity guarantees of the standard containers?
- Remove spaces from std::string in C++
- How do I sort a std::vector by the values of a different std::vector?
- problem sorting using member function as comparator
- How to initialize std::vector from C-style array?
- string c_str() vs. data()
- std::transform() and toupper(), no matching function
- Case insensitive std::string.find()
- Does std::list::remove method call destructor of each removed element?
- What is the difference between const_iterator and non-const iterator in the C++ STL?
- Is it reasonable to use std::basic_string as a contiguous buffer when targeting C++03?
- Should I store entire objects, or pointers to objects in containers?
- How can currying be done in C++?
- Why don’t the std::fstream classes take a std::string?
- how portable is end iterator decrement?
- Sorting a std::vector by the string?
- Template class with template container
- Windows Unicode C++ Stream Output Failure
- Can raw pointers be used instead of iterators with STL algorithms for containers with linear storage?
- std::back_inserter for a std::set?
- Converting between C++ std::vector and C array without copying
- C++, can I statically initialize a std::map at compile time?
- “Proper” way to store binary data with C++/STL
- C++ template function compiles in header but not implementation
- Insert into an STL queue using std::copy
- Why the sequence-operation algorithms predicates are passed by copy?