Re: std::vector filtering
Quote:
Originally Posted by
laasunde
Using std::sort appear to solve the ability to sort the collection.
How can I return an iterator to the client which only iterates a sub-set of all items in the std::vector?
Have a look at boost::filter_iterator. If the data is sorted, you can also use std::equal_range.
Quote:
Originally Posted by
laasunde
An example would be, I add this method to the class;
Code:
void find(const std::string& st);
So if the client performs (below) only items in std::vector that contains the character "a" should be possible to iterate.
Code:
foo f;
f.search("a");
One option would be to operate with two collection inside the foo class. One more static containing all items and the other containing the sorted and filtered items. This would lead to some copying but should work. Far from perfect. Any other ideas?
Instead of adding member functions for each algorithm, why not just reuse the STL algorithms. There is a std::find that takes a pair of iterators. From what I can tell, you can already use that with your current code.
Re: std::vector filtering
Thank you. Will take a look at what you mentioned.