Queue does not allow iteration through its elements.
From the SGI STL Docs:
A queue is an adaptor that provides a
restricted subset of Container
functionality A queue is a "first in
first out" (FIFO) data structure. [1]
That is, elements are added to the
back of the queue and may be removed
from the front; Q.front() is the
element that was added to the queue
least recently. Queue does not allow
iteration through its elements. [2]
You can make this work, but you can't use insert_iterator
. You'll have to write something like queue_inserter
that presents an iterator interface.
Update I couldn't help myself and deicded to try to implement the iterator 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 functions like this:
template<typename II, typename OI>
void mycopy(II b, II e, OI oi) {
while (b != e) { *oi++ = *b++; }
}
But it doesn't work with the STL copy because the STL is stupid.