Crbegin method in STL vector (7)

Source: Internet
Author: User

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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.