◐ Shell
clean mode source ↗

std::advance - cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

Definido no cabeçalho

<iterator>

template< class InputIt, class Distance > void advance( InputIt& it, Distance n );

Incrementos iterador determinado it por n elementos.

Original:

Increments given iterator it by n elements.

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

Se n é negativo, o iterador é diminuído. Neste caso, InputIt deve satisfazer os requisitos de BidirectionalIterator, caso contrário, o comportamento é indefinido.

Original:

If n is negative, the iterator is decremented. In this case, InputIt must meet the requirements of BidirectionalIterator, otherwise the behavior is undefined.

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

Parâmetros

it -

iterador a ser avançado

Original:

iterator to be advanced

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

n -

número de elementos it deve ser avançado

Original:

number of elements it should be advanced

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

Type requirements
-InputIt must meet the requirements of InputIterator.

Valor de retorno

(Nenhum)

Original:

(none)

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

Complexidade

Linear.

Original:

Linear.

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

No entanto, se, adicionalmente, InputIt cumpre os requisitos da RandomAccessIterator, a complexidade é constante.

Original:

However, if InputIt additionally meets the requirements of RandomAccessIterator, complexity is constant.

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

Exemplo

#include <iostream>
#include <iterator>
#include <vector>

int main() 
{
    std::vector<int> v{ 3, 1, 4 };
    
    auto vi = v.begin();

    std::advance(vi, 2);

    std::cout << *vi << '\n';
}

Saída:

Veja também

retorna a distância entre dois iteradores

Original:

returns the distance between two iterators

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


(função) [edit]