public member function
<unordered_map>

std::unordered_multimap::cend

container iterator (1)
const_iterator cend() const noexcept;
bucket iterator (2)
const_local_iterator cend ( size_type n ) const;
返回指向結尾的 const_iterator
返回一個const_iteratorpointing to the past-the-end element in the unordered_multimap container (1) or in one of its buckets (2).

要放回的字元的const_iteratorreturned bycenddoes not point to any element, but to the position that follows the last element in the unordered_multimap container or in one of its buckets (i.e., their past-the-end position). Thus, the value returned shall not be dereferenced - it is generally used to describe the open-end of a range, such as[cbegin,cend).

Notice that an unordered_multimap object makes no guarantees on which order its elements follow. But, in any case, the range that goes from itscbeginto itscendcovers all the elements in the container (or the bucket), until invalidated.

Aconst_iterator是一個指向常量內容的迭代器。這個迭代器可以像iteratorreturned by unordered_multimap::end, but it cannot be used to modify the contents it points to.

引數

n
Bucket number. This shall be lower than bucket_count.
It is an optional parameter that changes the behavior of this member function: if set, theconst_iteratorretrieved points to the past-the-end element of a bucket, otherwise it points to the past-the-end element of the container.
成員型別size_type是一種無符號整型型別。

返回值

Aconst_iteratorto the element past the end of the container (2) or the bucket (2).

兩者都const_iteratorconst_local_iteratorare member types. In the unordered_multimap class template, these are forward iterator types.
const_local_iteratoris an interator of the same category asconst_iterator. Theirvalue_type, difference_type, 指標引用member types are also the same. But the iterators themselves are not necessarily of the same type.

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// unordered_multimap::cbegin/cend example
#include <iostream>
#include <unordered_map>

int main ()
{
  std::unordered_multimap<std::string,std::string> myumm = {
    {"apple","red"},
    {"apple","green"},
    {"orange","orange"},
    {"strawberry","red"}
  };

  std::cout << "myumm contains:";
  for ( auto it = myumm.cbegin(); it != myumm.cend(); ++it )
    std::cout << " " << it->first << ":" << it->second;  // cannot modify *it
  std::cout << std::endl;

  std::cout << "myumm's buckets contain:\n";
  for ( unsigned i = 0; i < myumm.bucket_count(); ++i) {
    std::cout << "bucket #" << i << " contains:";
    for ( auto local_it = myumm.cbegin(i); local_it!= myumm.cend(i); ++local_it )
      std::cout << " " << local_it->first << ":" << local_it->second;
    std::cout << std::endl;
  }

  return 0;
}

可能的輸出
myumm contains: apple:red apple:green orange:orange strawberry:red
myumm's buckets contain:
bucket #0 contains:
bucket #1 contains:
bucket #2 contains: apple:red apple:green
bucket #3 contains: orange:orange
bucket #4 contains: strawberry:red


複雜度

常量。

迭代器有效性

沒有變化。

另見