std::deque: How do I get an iterator pointing to the element at a specified index?

Posted by Ptah- Opener of the Mouth on Stack Overflow See other posts from Stack Overflow or by Ptah- Opener of the Mouth
Published on 2010-04-09T15:17:03Z Indexed on 2010/04/09 15:23 UTC
Read the original article Hit count: 360

Filed under:
|
|
|

I have a std::deque, and I want to insert an element at a specified index (I'm aware that std::list would be better at this). The deque::insert() function takes an iterator to specify the location to insert. Given an index, how can I get an iterator pointing to that location, so that I can pass that iterator to insert()?

For example:

void insertThing ( deque<Thing> & things, Thing thing, size_t index )
{
   deque<Thing>::iterator it = /* what do I do here? */
   things.insert ( it, thing );
}

I'm sure this is a very basic question, and I apologize for it. It's been a long time since I've used the STL, and I don't see anything in std::deque's member list that obviously does what I want. Thanks.

© Stack Overflow or respective owner

Related posts about c++

Related posts about stl