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});
}
输出
[编辑] 亦参见
|
访问最后一个元素 (public member function) [编辑] |