std::deque push_front() method
- od C++11
- do C++11
// (1) Non const version only
void push_front( const T& value );
// (2) Non const version only
void push_front( T&& value );
// (1) Non const version only
void push_front( const T& value );
Prepends the given element value to the beginning of the container
Invalidation
All iterators, including the past-the-end iterator, are invalidated.
No references are invalidated.
Parameters
value
- the value of the element to prepend
Return value
(none)
Complexity
Constant - O(1).
Exceptions
If an exception is thrown, this function has no effect (strong exception guarantee).
Example
Main.cpp
#include <deque>
#include <iostream>
#include <iomanip>
#include <string>
int main()
{
std::deque<std::string> letters;
letters.push_front("abc");
std::string s{"def"};
letters.push_front(std::move(s));
std::cout << "std::deque `letters` holds: ";
for (auto&& e : letters) std::cout << std::quoted(e) << ' ';
std::cout << "\nMoved-from string `s` holds: " << std::quoted(s) << '\n';
}
Output
std::deque `letters` holds: "def" "abc"
Moved-from string `s` holds: ""
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.
Hover to see the original license.