public member function
<deque>

std::deque::cbegin

const_iterator cbegin() const noexcept;
返回指向開頭的 const_iterator
返回一個const_iterator指向容器中的第一個元素。

Aconst_iterator是一個指向常量內容的迭代器。這個迭代器可以像iteratorreturned by deque::begin, but it cannot be used to modify the contents it points to, even if the deque object is not itself const.

If the container is empty, the returned iterator value shall not be dereferenced.

引數



返回值

Aconst_iterator指向序列的開頭。

成員型別const_iteratoris a random access iterator type that points to a const element.

示例

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

int main ()
{
  std::deque<int> mydeque = {10,20,30,40,50};

  std::cout << "mydeque contains:";

  for (auto it = mydeque.cbegin(); it != mydeque.cend(); ++it)
    std::cout << ' ' << *it;

  std::cout << '\n';

  return 0;
}

輸出
mydeque contains: 10 20 30 40 50


複雜度

常量。

迭代器有效性

沒有變化。

資料競爭

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

異常安全

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

另見