Hi Paul!
On Friday, June 3, 2016 at 4:40:11 PM UTC-4, Paul wrote:
> ...
> > > However, I want to express the fact that the vector only contains iterators to charList; With the above code, itrs could contain iterators to any list<char> and I don't want that
> ...
> Thanks to both of you for your advice. However, my issue is that I would prefer it if vector<list<char>::iterator> was instead a container which is restricted to only containing iterators of the particular list<char> which I called characters; rather than accepting any list<char>::iterator.
I don't think you can do what you want with the type system.
The closet I can think of would be to wrap your list<char>
in its own class, and only instantiate one instance of
it (make it a singleton or just use discipline). Then use
a vector<MyCharList::iterator>.
There is a similar issue already in the library. A number
of algorithm templates take a start and end iterator. They
have to be iterators of the same type, but nothing in the
type or template system can enforce that they point into
the same collection. (Probably undefined behavior if they
don't.) One solution would be to have algorithms that take
a range object (that might be a wrapper for a pair of
iterators). If range objects can only be constructed from
instances of collections, the constructors can enforce that
both ends of the range point into the same collection.
> Paul
Good luck.
K. Frank