public member function
<unordered_set>

std::unordered_set::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_set 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_set 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_set 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_iteratoris an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), but it cannot be used to modify the contents it points to.

参数

n
存储桶编号。此值应小于 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_set class template, these are forward iterator types.
They may both be aliases of the same iterator 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
// unordered_set::cbegin/cend example
#include <iostream>
#include <string>
#include <unordered_set>

int main ()
{
  std::unordered_set<std::string> myset =
  {"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"};

  std::cout << "myset contains:";
  for ( auto it = myset.cbegin(); it != myset.cend(); ++it )
    std::cout << " " << *it;    // cannot modify *it
  std::cout << std::endl;

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

  return 0;
}

可能的输出
myset contains: Venus Jupiter Neptune Mercury Earth Uranus Saturn Mars
myset's buckets contain:
bucket #0 contains:
bucket #1 contains: Venus
bucket #2 contains: Jupiter
bucket #3 contains: 
bucket #4 contains: Neptune Mercury
bucket #5 contains: 
bucket #6 contains: Earth
bucket #7 contains: Uranus Saturn
bucket #8 contains: Mars
bucket #9 contains: 
bucket #10 contains: 


复杂度

常量。

迭代器有效性

没有变化。

另见