名前空間
変種
操作

std::span<T,Extent>::front

From cppreference.com
< cpp‎ | container‎ | span
 
 
 
 
constexpr reference front() const;
(C++20以降)

spanの最初の要素への参照を返します。

空のspanに対してfrontを呼び出すと、未定義の動作が発生します。

目次

[編集] パラメータ

(なし)

[編集] 戻り値

最初の要素への参照。

[編集] 計算量

定数。

[編集] 注記

span cに対して、式 c.front()*c.begin() と同等です。

[編集]

#include <iostream>
#include <span>
 
void print(std::span<const int> const data)
{
    for (auto offset{0U}; offset != data.size(); ++offset)
        std::cout << data.subspan(offset).front() << ' ';
    std::cout << '\n';
}
 
int main()
{
    constexpr int data[]{0, 1, 2, 3, 4, 5, 6};
    print({data, 4});
}

出力

0 1 2 3

[編集] 関連項目

最後の要素にアクセスする
(public メンバ関数) [編集]
English 日本語 中文(简体) 中文(繁體)