In C++, std::deque::insert() adds new elements to a std::dequebefore a position that you give as an iterator. Everything from that position onward moves one place further back to make room.
You can insert one value, several copies of a value, a range from another container, or a braced list. Include <deque> to use it.
This is a member of std::deque<T>, a double-ended queue. A deque is fast at adding and removing at both ends, and it allows access by index like std::vector. Unlike a vector, its elements are stored in several blocks, not in one contiguous block.
Syntax
The first argument is always the position (an iterator). The rest describes what to add.
C++
d.insert(d.begin() + 1, 20); // one value
d.insert(d.begin() + 1, 3, 0); // three zeros
d.insert(d.end(), v.begin(), v.end()); // a range
d.insert(d.begin(), {1, 2}); // a list
Call
What it does
d.insert(pos, value)
Adds one copy of value before pos.
d.insert(pos, count, value)
Adds count copies of value before pos.
d.insert(pos, first, last)
Adds every element of the range [first, last) before pos.
d.insert(pos, {1, 2})
Adds the values of the braced list before pos.
Inserting at begin() or end() is fast. For those two places, push_front() and push_back() are simpler.