November 26th, 2012, 08:03 AM
The example enable a client to iterate the internal std::vector using being() and end().
In the future I see the need for this class to be able to control sequence (sorting) and also show a subset of the complete list based on a search parameter.
typedef std::vector<std::string>const_iterator iter;
iter begin () const;
iter end () const;
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?
An example would be, I add this method to the class;
So if the client performs (below) only items in std::vector that contains the character "a" should be possible to iterate.
void find(const std::string& st);
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?
, make an effort yourself, try googling
or search here
, give a proper description of your problem, include code* and error messages.
*All code should include code tags
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!