
Ion GaztaƱaga <igaztanaga@gmail.com> writes:
Hi to all,
Trying to simplify containers' code in Boost.Interprocess, I've seen that an iterator that simulates a range of values from a single value is useful to implement functions taking a value and a count in containers:
template<class T, class A> class vector { //... void insert (iterator position, size_type n, const T& x); void assign (size_type n, const T& x); };
My intention was to reuse the code for "insert" and "assign" taking iterators to avoid nearly duplicating the code (which is quite complex in vector, deque and basic_string). This way, I've created an iterator called "range_from_ref_iterator" that can be used to implement the "insert" function taking a value and a count like this:
You haven't really explained what this thing is supposed to be doing. As far as I can tell from the code, it dereferences to the same location at each position. If that's really what you intend, you ought to do something to ensure that its iterator category doesn't indicate it satisfies forward iterator requirements.
Do you think this iterator is a good addition to boost iterator library? Obviously it can be more refined. It could take the external value by reference or store a copy depending on the type. But I think it can be useful. I'm open to write the documentation following Boost.Iterator style if this iterator is considered useful (I'm open also to let others do the hard work, of course). Comments?
Seems like a reasonable idea, but I'm not sure whether it's useful enough to be included. I'd definitely call it something other than range_from_ref_iterator, though. constant_iterator or something like that seems appropriate. -- Dave Abrahams Boost Consulting www.boost-consulting.com