In fact, crbegin is equivalent to cbegin + rbegin. For the two functions, see my previous two blog posts.
Public member function <vector> STD: vector: crbegin
const_reverse_iterator crbegin() const noexcept;
Return const_reverse_iterator to reverse beginningreturns Const_reverse_iteratorPointing to the last element in the container (I. e., its
Reverse beginning).
This function returns a reverse_iterator with the const attribute, pointing to the last element of the container.
Parametersnone
Return valuea Const_reverse_iteratorTo
Reverse beginningOf the sequence.
The returned value is a reverse iterator with the const attribute pointing to the reverse beginning of the sequence.
Member type Const_reverse_iteratorIs a reverse Random Access iterator type that points to a const element (see vector member types ).
The type of the returned value belongs to the reverse type of the random access iterator.
Example
123456789101112131415
|
// vector::crbegin/crend#include <iostream>#include <vector>int main (){ std::vector<int> myvector = {1,2,3,4,5}; std::cout << "myvector backwards:"; for (auto rit = myvector.crbegin(); rit != myvector.crend(); ++rit) std::cout << ‘ ‘ << *rit; std::cout << ‘\n‘; return 0;}
|
Edit & run |
Output:
myvector backwards: 5 4 3 2 1 |
Complexityconstant.
Iterator validityno changes.
Data racesthe container is accessed.
No contained elements are accessed by the call, but the iterator returned can be used to access them. Concurrently accessing or modifying different elements is safe.
This method does not actually access elements in the container, but the returned iterator can be used to access elements and use them to access or modify different elements. (Is there a problem here? Use const_cast to convert? It seems that this cannot be converted. What is the situation ?)
Exception safety
No-throw guarantee:This member function never throws exceptions.
The copy construction or assignment of the returned iterator is also guaranteed to never throw.
This method does not throw an exception.
Copying an iterator using the copy constructor or the value assignment operation will not throw an exception.
// If the translation is poor, please give me more guidance. You can leave a message below or click the email address in the upper-left corner to send me an email, pointing out my errors and deficiencies, so that I can modify them, thank you for sharing it.
Reprinted please indicate the source: http://blog.csdn.net/qq844352155
November
Yu gdut