std::vector<T,Allocator>::front
From cppreference.com
| reference front(); |
(1) | (C++20 以降 constexpr) |
| const_reference front() const; |
(2) | (C++20 以降 constexpr) |
コンテナの最初の要素への参照を返します。
空のコンテナに対してfrontを呼び出すと、未定義の動作を引き起こします。
目次 |
[編集] 戻り値
最初の要素への参照。
[編集] 複雑性
定数。
[編集] 注記
コンテナcについて、式 c.front() は *c.begin() と同等です。
[編集] 例
以下のコードは、front を使用して、std::vector<char> の最初の要素を表示します。
このコードを実行
#include <cassert> #include <vector> int main() { std::vector<char> letters{'a', 'b', 'c', 'd'}; assert(letters.front() == 'a'); }
[編集] 関連項目
| 最後の要素にアクセスする (public メンバ関数) | |
| (C++11) |
末尾への逆イテレータを返す (public メンバ関数) |
| (C++11) |
先頭へのイテレータを返す (public メンバ関数) |
| 基底となる連続ストレージに直接アクセスする (public メンバ関数) |