The queue does not allow iteration through its elements.
From SGI STL Docs :
A queue is an adapter that provides a limited subset of the container. Functionality A queue is the first in (FIFO). 1 That is, items are added to the back of the queue and can be removed from the front; Q.front () is an item added to the queue in Recently, the queue does not allow iteration through its elements. [2]
You can do this work, but you cannot use insert_iterator . You need to write something like queue_inserter that represents the iterator interface.
Update . I could not help myself and try to implement the iterator that you need. Here are the results:
template< typename T, typename U > class queue_inserter { queue<T, U> &qu; public: queue_inserter(queue<T,U> &q) : qu(q) { } queue_inserter<T,U> operator ++ (int) { return *this; } queue_inserter<T,U> operator * () { return *this; } void operator = (const T &val) { qu.push(val); } }; template< typename T, typename U > queue_inserter<T,U> make_queue_inserter(queue<T,U> &q) { return queue_inserter<T,U>(q); }
This works great for features like this:
template<typename II, typename OI> void mycopy(II b, II e, OI oi) { while (b != e) { *oi++ = *b++; } }
But this does not work with a copy of STL, because STL is stupid.
Frank Krueger Nov 12 '09 at 16:38 2009-11-12 16:38
source share