The unordered_map::cend() is a built-in function in C++ STL which returns an iterator pointing to the position past the end element in the container or in one of its bucket. In an unordered_map object, there is no guarantee that which specific element is considered its first element. But all the elements in the container are covered since the range goes from its begin to its end until invalidated.
There are two variant of this function.
Parameters: This function does not accept any parameter.
Return type: The function returns an iterator to the element past the end of the container.
5 6 1 2 3 4
unordered_map.cend ( size n )
Parameters: This function accepts parameter size n which should be lower than bucket count.
Return type: The function returns an iterator to the one of its bucket count.
unordered_map bucket contains Bucket 0 contains Bucket 1 contains 1 2 Bucket 2 contains Bucket 3 contains 3 4 Bucket 4 contains Bucket 5 contains 5 6 Bucket 6 contains
How is cend() different from end()?
cend() is const version of end(). Similarly cbegin() is a const version of begin(). For example, the following code shows compiler error because we try to modify value in iterator.
Compilation Error in CPP code :- prog.cpp: In function 'int main()': prog.cpp:19:20: error: assignment of member 'std::pair
::second' in read-only object it->second = 10; // COMPILER ERROR
- forward_list::cend() in C++ STL with Example
- unordered_multiset cend() function in C++ STL
- unordered_multimap cend() function in C++ STL
- match_results cbegin() add cend() in C++ STL
- unordered_set cend() function in C++ STL
- map cbegin() and cend() function in C++ STL
- set cbegin() and cend() function in C++ STL
- list cbegin() and cend() function in C++ STL
- multiset cbegin() and cend() function in C++ STL
- array::cbegin() and array::cend() in C++ STL
- multimap::cbegin() and multimap::cend() in C++ STL
- vector :: cbegin() and vector :: cend() in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.