I would like to code a method capable of returning a range of iterators to represent a subset of a bigger list.
Can such “subset” not have being made of contiguous objects ?
For example, if I have a std::list with n objects.
eg.
| object1 | object2 | object3 | object4 | ... | objectn
Can I return a range of iterators (a pair of begin / end we can call ItBegin and ItEnd) which would include only Object 1,3 and 4 ?
eg.
| object1 | object2 | object3 | object4 | ... | objectN
^ ^ ^ ^
| | | |
ItBegin ++ItBegin ++ItBegin ItEnd
Is that possible or do I need to copy the objects (or use pointers to avoid the copy) onto a new list and return that list ?
Please note that the iterator(s) subset would just be used for reading. (a pair of const_iterator would do the job)
Thanks!
Giacomo
If you don’t mind using Boost, you could use filter_iterator, e.g.
Also, if the thing you are reading to can be made into an output iterator, you could just use
std::remove_copy_if.