public member function
<set>

std::set::end

      iterator end();const_iterator end() const;
      iterator end() noexcept;const_iterator end() const noexcept;
返回指向末尾的迭代器
返回一個指向 set 容器中“尾後”元素的迭代器。

“尾後”元素是 set 容器中最後一個元素之後的理論上的元素。它不指向任何元素,因此不應被解引用。

由於標準庫函式的範圍不包含其結束迭代器指向的元素,此函式通常與 set::begin 結合使用,以指定包含容器中所有元素的範圍。

如果容器是 空的,此函式返回的值與 set::begin 相同。

引數



返回值

指向容器中“尾後”元素的迭代器。

如果 set 物件是 const 限定的,則函式返回一個const_iterator。否則,它返回一個iterator.

成員型別iteratorconst_iterator是指向元素的 雙向迭代器 型別。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// set::begin/end
#include <iostream>
#include <set>

int main ()
{
  int myints[] = {75,23,65,42,13};
  std::set<int> myset (myints,myints+5);

  std::cout << "myset contains:";
  for (std::set<int>::iterator it=myset.begin(); it!=myset.end(); ++it)
    std::cout << ' ' << *it;

  std::cout << '\n';

  return 0;
}

輸出
myset contains: 13 23 42 65 75


複雜度

常量。

迭代器有效性

沒有變化。

資料競爭

訪問容器(const 和非 const 版本都不會修改容器)。
併發訪問set的元素是安全的。

異常安全

無異常保證:此成員函式從不丟擲異常。
還可以保證返回的迭代器的複製構造或賦值永遠不會引發異常。

另見