1

Possible Duplicate:
How to find an item in a std::vector?

I am using C++ Builder to create a VCL Forms application. I also have a vector array of appointment objects that each have a name, type, reminder date/time, a date/time, location and comments.

I am wanting to implement a find feature that will let a user find an appointment given certain criteria.

The user can choose to find an appointment in the vector array by either choosing the name, type etc or a combination of each.

What would be the best programming concept to use for this situation? The vector is not large. No more than 10 or 20 elements.

Thanks

Community
  • 1
  • 1
user1690531
  • 231
  • 1
  • 6
  • 17

3 Answers3

2

Use std::find_if() and define the required predicate (if C++11 you can use lambda function).

See online demo http://ideone.com/Md7sp.

hmjd
  • 120,187
  • 20
  • 207
  • 252
1
std::find_if(A.begin(),A.end(),isthatit(conditions));

where isthatit is a predicate object constructed from conditions.

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
0

If you have many criterias you should think about Boost.MultiIndex container which targets different search indexes. http://www.boost.org/doc/libs/1_51_0/libs/multi_index/doc/tutorial/index.html

Eugene Mamin
  • 749
  • 4
  • 8