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

履歴 編集

function
<list>

std::list::push_front

void push_front(const T& x); // (1)
void push_front(T&& x);      // (2) C++11

概要

新たな要素を先頭に追加する。

戻り値

なし

計算量

定数時間

#include <iostream>
#include <list>
#include <string>
#include <algorithm>

int main()
{
  std::list<std::string> ls;

  // const&バージョン
  std::string s = "world";
  ls.push_front(s);

  // &&バージョン
  ls.push_front(std::string("hello"));

  for (const std::string& x : ls) {
    std::cout << x << std::endl;
  };
}

出力

hello
world