public member function
<map>

std::map::cend

const_iterator cend() const noexcept;
返回指向結尾的 const_iterator
返回一個const_iterator指向容器的尾後元素。

Aconst_iterator是一個指向常量內容的迭代器。這個迭代器可以像iteratormap::end 返回,但即使 map 物件本身不是 const,也不能用於修改它所指向的內容。

如果容器是 empty 的,此函式返回的內容與 map::cbegin 相同。

返回的值不應被解引用。

引數



返回值

Aconst_iterator指向序列末尾的元素。

成員型別const_iterator是一個指向 const 元素的 雙向迭代器 型別。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// map::cbegin/cend
#include <iostream>
#include <map>

int main ()
{
  std::map<char,int> mymap;

  mymap['b'] = 100;
  mymap['a'] = 200;
  mymap['c'] = 300;

  // print content:
  std::cout << "mymap contains:";
  for (auto it = mymap.cbegin(); it != mymap.cend(); ++it)
    std::cout << " [" << (*it).first << ':' << (*it).second << ']';
  std::cout << '\n';

  return 0;
}

輸出
mymap contains: [a:200] [b:100] [c:300]


複雜度

常量。

迭代器有效性

沒有變化。

資料競爭

訪問容器。
呼叫不訪問任何容器中的元素,但返回的迭代器可用於訪問它們。併發訪問或修改不同元素是安全的。

異常安全

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

另見