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

履歴 編集

function
<list>

std::list::back

reference back();             // (1)
const_reference back() const; // (2)

概要

末尾要素への参照を取得する

戻り値

末尾の要素への参照を返す。

a.back(){ auto tmp = a.end(); --tmp; return *tmp; } と同じ結果になる。

計算量

定数時間

#include <iostream>
#include <list>

int main()
{
  std::list<int> ls = {3, 1, 4};

  int& x = ls.back();
  std::cout << x << std::endl;
}

出力

4