名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | 容器‎ | 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 member function) [編輯]