std::span<T,Extent>::end, std::span<T,Extent>::cend
来自cppreference.com
constexpr iterator end() const noexcept; |
(1) | (C++20 起) |
constexpr const_iterator cend() const noexcept; |
(2) | (C++23 起) |
返回指向 *this 的尾后元素的迭代器。
返回的迭代器仅表现为哨位。不保证它可解引用。
目录 |
[编辑] 返回值
指向尾后元素的迭代器。
[编辑] 复杂度
常数。
[编辑] 示例
运行此代码
#include <iostream> #include <span> void print(std::span<const int> array) { std::cout << "array = "; for (auto it = array.begin(); it != array.end(); ++it) std::cout << *it << ' '; std::cout << '\n'; } void set_first_element(std::span<int> sp, int new_value) { if (!sp.empty()) { std::cout << "old *begin = " << *sp.begin() << '\n'; *sp.begin() = new_value; std::cout << "new *begin = " << *sp.begin() << '\n'; } } int main() { int array[]{1, 3, 4, 5}; print(array); set_first_element(array, 2); print(array); }
输出:
array = 1 3 4 5 old *begin = 1 new *begin = 2 array = 2 3 4 5
[编辑] 参阅
(C++23) |
返回指向起始的迭代器 (公开成员函数) |
(C++11)(C++14) |
返回指向容器或数组结尾的迭代器 (函数模板) |