名前空間
変種
操作

std::forward_list<T,Allocator>::front

提供: cppreference.com
 
 
 
 
reference front();
(C++11以上)
const_reference front() const;
(C++11以上)

コンテナ内の最初の要素を指す参照を返します。

空のコンテナに対する front の呼び出しは未定義です。

目次

[編集] 引数

(なし)

[編集] 戻り値

最初の要素を指す参照。

[編集] 計算量

一定。

[編集] ノート

コンテナ c に対して、式 c.front()*c.begin() と同等です。

[編集]

以下のコードは front を使用して std::forward_list<char> の最初の要素を表示します。

#include <forward_list>
#include <iostream>
 
int main()
{
    std::forward_list<char> letters {'o', 'm', 'g', 'w', 't', 'f'};
 
    if (!letters.empty()) {
        std::cout << "The first character is: " << letters.front() << '\n';
    }  
}

出力:

The first character is o