unordered_multiset cend() function in C++ STL

The unordered_multiset::cend() is a built-in function in C++ STL which returns a constant iterator pointing to the position immediately after the last element in the container or to the position immediately after the last element in one of its bucket.

Syntax:

unordered_multiset_name.cend(n)

Parameters: The function accepts one parameter. If a parameter is passed, it returns a constant iterator pointing to the position immediately after the last element in the bucket. If no parameter is passed, then it returns a constant iterator pointing to the position immediately after the last element in the unordered_multiset container.

Return Value: It returns a constant iterator. It cannot be used to modify the content of the container.

Below programs illustrate the above function:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::cend() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<int> sample;
  
    // inserts element
    sample.insert(10);
    sample.insert(15);
    sample.insert(15);
    sample.insert(13);
    sample.insert(13);
  
    cout << "\nElements: ";
  
    // prints all element till the last
    for (auto it = sample.cbegin(); it != sample.cend(); it++)
        cout << *it << " ";
    return 0;
}
chevron_right

Output:
Elements: 13 13 10 15 15

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::cend() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<char> sample;
  
    // inserts element
    sample.insert('a');
    sample.insert('b');
    sample.insert('b');
    sample.insert('b');
    sample.insert('z');
  
    cout << "\nElements: ";
  
    // prints all element
    for (auto it = sample.cbegin(); it != sample.cend(); it++)
        cout << *it << " ";
    return 0;
}
chevron_right

Output:
Elements: z a b b b

Program 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::cend() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<char> sample;
  
    // inserts element
    sample.insert('a');
    sample.insert('b');
    sample.insert('b');
    sample.insert('b');
    sample.insert('z');
  
    // prints all element bucket wise
  
    for (int i = 0; i < sample.bucket_count(); i++) {
  
        cout << "Bucket " << i << ": ";
  
        // if bucket is empty
        if (sample.bucket_size(i) == 0)
            cout << "empty";
  
        for (auto it = sample.cbegin(i); it != sample.cend(i); it++)
            cout << *it << " ";
  
        cout << endl;
    }
    return 0;
}
chevron_right

Output:
Bucket 0: b b b 
Bucket 1: empty
Bucket 2: empty
Bucket 3: z 
Bucket 4: empty
Bucket 5: empty
Bucket 6: a

Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.





The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
C++
Practice Tags :