std::end
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <iterator> 中定义
|
||
| template< class C > auto end( C& c ) -> decltype(c.end()); |
(1) | (C++11 起) |
| template< class C > auto end( const C& c ) -> decltype(c.end()); |
(2) | (C++11 起) |
| template< class T, size_t N > T* end( T (&array)[N] ); |
(3) | (C++11 起) |
返回一个迭代结束(即最后一个元素的元素后)给定的容器
c或数组array.原文:
Returns an iterator to the end (i.e. the element after the last element) of the given container
c or array array.目录 |
[编辑] 参数
| c | - | 的容器具有
end方法 |
| array | - | 任意类型的数组
|
[编辑] 返回值
c或array年底的迭代器。请注意,一个容器或数组的元素被定义为结束后,最后的有效元件.原文:
an iterator to the end of
c or array. Note that the end of a container or array is defined as the element following the last valid element.[编辑] 注释
除了被包括在
<iterator>std::end保证变得可用,如果没有下面的接头连接器包括:<array>,<deque>,<forward_list>,<list>,<map>,<regex>,<set>,<string>,<unordered_map>,<unordered_set>,并<vector>.原文:
In addition to being included in
<iterator>, std::end is guaranteed to become available if any of the following headers are included: <array>, <deque>, <forward_list>, <list>, <map>, <regex>, <set>, <string>, <unordered_map>, <unordered_set>, and <vector>.[编辑] 专业化
定制专业的
std::end可能会不露出一个合适的end()成员函数的类,还可以迭代。以下专业的标准库已经提供了原文:
Custom specializations of
std::end may be provided for classes that do not expose a suitable end() member function, yet can be iterated. The following specializations are already provided by the standard library:| 模板特化 std::end (函数模板) | |
| (C++11) |
模板特化 std::end (函数模板) |
[编辑] 示例
#include <iostream> #include <vector> #include <iterator> #include <algorithm> int main() { std::vector<int> v = { 3, 1, 4 }; if (std::find(std::begin(v), std::end(v), 5) != std::end(v)) { std::cout << "found a 5 in vector v!\n"; } int a[] = { 5, 10, 15 }; if (std::find(std::begin(a), std::end(a), 5) != std::end(a)) { std::cout << "found a 5 in array a!\n"; } }
输出:
found a 5 in array a!
[编辑] 另请参阅
| (C++11) |
返回一个迭代器的容器或数组的开始 原文: returns an iterator to the beginning of a container or array (函数) |