What's the best way to return a subset of a list
Posted
by
Pikrass
on Stack Overflow
See other posts from Stack Overflow
or by Pikrass
Published on 2010-12-27T02:41:23Z
Indexed on
2010/12/27
2:54 UTC
Read the original article
Hit count: 194
I have a list of tasks. A task is defined by a name, a due date and a duration.
My TaskManager class handles a std::list<Task>
sorted by due date. It has to provide a way to get the tasks due for a specific date.
How would you implement that ?
I think a good way (from API point of view) would be to provide a std::list<Task>::iterator
pair. So I would have a TaskManager::begin(date)
method. Do you think this method should get the iterator by iterating from the start of the list until it finds the first task due on that date, or by getting it from a std::map<date, std::list<Task>::iterator>
(but then we have to keep it up-to-date when adding or removing tasks) ?
And then, how could I implement the TaskManager::end(date)
method ?
© Stack Overflow or respective owner