std::forward_list<T,Allocator>::end, std::forward_list<T,Allocator>::cend
来自cppreference.com
< cpp | container | forward list
容器库
std::forward_list
成员函数 | ||||
元素访问 | ||||
迭代器 | ||||
forward_list::endforward_list::cend
|
||||
容量 | ||||
修改器 | ||||
操作 | ||||
非成员函数 | ||||
(C++20)(C++20)
|
||||
(C++20
前)(C++20
前)(C++20
前)(C++20
前)(C++20
前)(C++20)
|
||||
推导指引(C++17) |
iterator
end()
noexcept;
|
(C++11 起) | |
const_iterator
end()
const
noexcept;
|
(C++11 起) | |
const_iterator
cend()
const
noexcept;
|
(C++11 起) | |
返回指向 forward_list
末元素后一元素的迭代器。
此元素表现为占位符;试图访问它导致未定义行为。
参数
(无)
返回值
指向后随最后元素的迭代器。
复杂度
常数。
示例
运行此代码
#include <iostream> #include <numeric> #include <forward_list> #include <string> int main() { std::forward_list<int> nums {1, 2, 4, 8, 16}; std::forward_list<std::string> fruits {"orange", "apple", "raspberry"}; std::forward_list<char> empty; // 求和 forward_list nums 中的所有整数(若存在),仅打印结果。 std::cout << "Sum of nums: " << std::accumulate(nums.begin(), nums.end(), 0) << "\n"; // 打印 forward_list fruits 中的首个 fruis ,不检查是否有一个。 std::cout << "First fruit: " << *fruits.begin() << "\n"; if (empty.begin() == empty.end()) std::cout << "forward_list 'empty' is indeed empty.\n"; }
输出:
Sum of nums: 31 First fruit: orange forward_list 'empty' is indeed empty.
参阅
(C++11)
|
返回指向起始的迭代器 (公开成员函数) |