◐ Shell
clean mode source ↗

std::reverse_iterator — cppreference.com

De cppreference.com

<tbody> </tbody>

Déclaré dans l'en-tête

<iterator>

template< class Iterator > class reverse_iterator : public std::iterator< typename std::iterator_traits<Iterator>::iterator_category, typename std::iterator_traits<Iterator>::value_type, typename std::iterator_traits<Iterator>::difference_type, typename std::iterator_traits<Iterator>::pointer, typename std::iterator_traits<Iterator>::reference >

std::reverse_iterator est un adaptateur d'itérateur qui inverse le sens d'un itérateur donné. En d'autres termes, lorsqu'il est fourni avec un itérateur bidirectionnel, std::reverse_iterator produit un nouvel itérateur qui se déplace depuis la fin jusqu'au début de la séquence définie par l'itérateur bidirectionnel sous-jacent.

Pour un std::reverse_iterator noté r construit à partir d'un itérateur i, la relation &*r == &*(i-1) est toujours vraie, donc un std::reverse_iterator construit à partir d'un itérateur pointant sur l'élément juste après la fin déréférence le dernier élément d'une séquence.

C'est l'itérateur retourné par les fonctions membres rbegin() et rend() des conteneurs de la bibliothèque standard.

Types de membres

Type de membre Définition
iterator_type Iterator
difference_type std::iterator_traits<Iterator>::difference_type
pointer std::iterator_traits<Iterator>::pointer
reference std::iterator_traits<Iterator>::reference

Fonctions membres

construit un nouvel itérateur adaptateur

Original:

constructs a new iterator adaptor

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction membre publique) [edit]

assigne un autre itérateur

Original:

assigns another iterator

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction membre publique) [edit]

accède à l'itérateur sous-jacent

Original:

accesses the underlying iterator

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction membre publique) [edit]

accède à l'élément pointé vers

Original:

accesses the pointed-to element

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction membre publique) [edit]

obtient de référence rvalue à l'élément indexé

Original:

obtains rvalue reference to indexed element

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction membre publique) [edit]

avances ou décrémente l'itérateur

Original:

advances or decrements the iterator

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction membre publique) [edit]

Objets membres

Nom du membre Définition
current (protégé) une copie de l'itérateur base()

En plus de la valeur courante de l'itérateur sous-jacent, une implémentation classique de std::reverse_iterator est de garder une copie de l'itérateur sous-jacent décrémenté, qui sera utilisé dans le déréférencement.

Fonctions tierces

compare les itérateurs sous-jacents

Original:

compares the underlying iterators

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction générique) [edit]

progrès de l'itérateur

Original:

advances the iterator

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction générique) [edit]

calcule la distance entre deux adaptateurs itérateur

Original:

computes the distance between two iterator adaptors

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction générique) [edit]

Inherited from std::iterator

Member types

Type du membre Définition
value_type std::iterator_traits<Iterator>::value_type
difference_type std::iterator_traits<Iterator>::difference_type
pointer std::iterator_traits<Iterator>::pointer
reference std::iterator_traits<Iterator>::reference
iterator_category std::iterator_traits<Iterator>::iterator_category

Exemple

#include <iostream>
#include <string>
#include <iterator>

int main()
{
    std::string s = "Hello, world";
    std::reverse_iterator<std::string::iterator> r = s.rbegin();
    r[7] = 'O'; // remplace 'o' avec 'O' 
    r += 7; // l'itérateur pointe désormais sur 'O'
    std::string rev(r, s.rend());
    std::cout << rev << '\n';
}

Résultat :

Voir aussi

l'itérateur de base

Original:

the basic iterator

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(classe générique) [edit]