Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ unordered_multiset::end function is used to return the iterator pointing to the past-the-last element of the unordered_multiset container or one of its bucket. The past-the-last element of the multiset is the theoretical element that follows the last element. It does not point to any element, and hence could not be dereferenced.

C++ begin end

Note: There is no guarantee on how elements are ordered in the unordered_multiset (or the bucket). But the range that goes from begin to end contains all elements of the unordered_multiset container (or the bucket).

Syntax

//container iterator
iterator end() noexcept;
const_iterator end() const noexcept;

//bucket iterator
local_iterator end ( size_type n );
const_local_iterator end ( size_type n ) const;

Parameters

n Specify the bucket number. It should be lower than the bucket_count.

Return Value

An iterator to the past-the-last element of the unordered_multiset container or one of its bucket. If the sequence object is constant qualified, the function returns a const_iterator, else returns an iterator.

Time Complexity

Constant i.e, Θ(1)

Example:

In the below example, the unordered_multiset::end function is used to return the iterator pointing to the past-the-last element of the unordered_multiset container or one of its bucket. The unordered_multiset::end function is often used with unordered_multiset::begin function to specify a range including all elements of the unordered_multiset container or one of its bucket.

#include <iostream>
#include <unordered_set>
using namespace std;
 
int main (){
  unordered_multiset<int> uMSet{55, 25, 128, 5, 72, -500, 45, 24, -20, 55, 25};

  cout<<"The uMSet contains: ";
  for(auto it = uMSet.begin(); it != uMSet.end(); ++it)
    cout<<*it<<" ";

  cout<<"\n\nThe uMSet's bucket contains: ";
  for(unsigned int i = 0; i < uMSet.bucket_count(); i++) {
    cout<<"\nThe bucket #"<<i<<" contains: ";   
    for(auto it = uMSet.begin(i); it != uMSet.end(i); ++it) {
      cout<<*it<<" ";
    } 
  } 
  return 0;
}

The output of the above code will be:

The uMSet contains: -20 45 -500 72 5 24 128 25 25 55 55 

The uMSet's bucket contains: 
The bucket #0 contains: 
The bucket #1 contains: 
The bucket #2 contains: 
The bucket #3 contains: 55 55 
The bucket #4 contains: 
The bucket #5 contains: 5 
The bucket #6 contains: 45 
The bucket #7 contains: 72 
The bucket #8 contains: 
The bucket #9 contains: -20 
The bucket #10 contains: -500 
The bucket #11 contains: 24 128 
The bucket #12 contains: 25 25 

❮ C++ - Unordered Multiset