最終更新日時(UTC):
が更新

履歴 編集

function
<deque>

std::deque::push_front

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;
  }
}

出力

hello
world

関連項目

名前 説明
push_back 末尾に要素を追加する
pop_front 先頭要素を削除する
insert 任意の位置に要素を挿入する

参照