函式模板
<iterator> <array> <deque> <forward_list> <list> <map> <regex> <set> <string> <unordered_map> <unordered_set> <vector>

std::end

容器 (1)
template <class Container>  auto end (Container& cont) -> decltype (cont.end());template <class Container>  auto end (const Container& cont) -> decltype (cont.end());
陣列 (2)
template <class T, size_t N>  T* end (T(&arr)[N]);
容器 (1)
template <class Container>  auto end (Container& cont) -> decltype (cont.end());template <class Container>  auto end (const Container& cont) -> decltype (cont.end());
陣列 (2)
template <class T, size_t N>  constexpr T* end (T(&arr)[N]) noexcept;
指向末尾的迭代器
返回一個指向序列中“越過末尾”元素的迭代器

(1) 容器
函式返回 cont.end()
(2) 陣列
函式返回 arr+N

如果序列是“空的”,則返回的值與使用相同引數呼叫 begin 所返回的值相等。

這些函式模板定義在多個頭檔案中:每個標頭檔案都包含所有容器和陣列型別的通用模板,而不僅僅是特定的過載。這些標頭檔案是: <iterator><array><deque><forward_list><list>map<regex><set><string><unordered_map><unordered_set><vector>

反之,end 在標頭檔案 <initializer_list><valarray> 中被過載(具有不同的定義)。

引數

cont
定義了成員 end 的類型別物件。
arr
一個數組。

返回值

對於 (1),與 cont.end() 返回的相同。
對於 (2),指向陣列最後一個元素之後位置的指標。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// std::begin / std::end example
#include <iostream>     // std::cout
#include <vector>       // std::vector, std::begin, std::end

int main () {
  int foo[] = {10,20,30,40,50};
  std::vector<int> bar;

  // iterate foo: inserting into bar
  for (auto it = std::begin(foo); it!=std::end(foo); ++it)
    bar.push_back(*it);

  // iterate bar: print contents:
  std::cout << "bar contains:";
  for (auto it = std::begin(bar); it!=std::end(bar); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}

輸出
bar contains: 10 20 30 40 50


資料競爭

引數被訪問但未被修改。
呼叫不會訪問序列中的任何元素,但返回的迭代器可用於訪問或修改它們。

異常安全

提供與對引數執行的操作相同的保證級別(對於標準容器和陣列,這是無異常保證)。

另見