- deque[meta header]
- std[meta namespace]
- deque[meta class]
- function[meta id-type]
void push_front(const T& x); // (1)
void push_front(T&& y); // (2) C++11先頭に要素を追加する。
- (1) :
xのコピーを先頭に追加する - (2) : 一時オブジェクト
xを移動して先頭に追加する
なし
定数時間
操作中に例外が発生した場合、副作用は発生しない。
#include <iostream>
#include <deque>
#include <string>
int main()
{
std::deque<std::string> c;
// const&バージョン
std::string s = "world";
c.push_front(s);
// &&バージョン
c.push_front(std::string("hello"));
for (auto x : c) {
std::cout << x << std::endl;
}
}- push_front[color ff0000]
hello
world
| 名前 | 説明 |
|---|---|
push_back |
末尾に要素を追加する |
pop_front |
先頭要素を削除する |
insert |
任意の位置に要素を挿入する |