命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | container‎ | span
constexpr reference front() const;
(since 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

[编辑] 参见

访问最后一个元素
(公开成员函数) [编辑]