◐ Shell
clean mode source ↗

std::advance – cppreference.com

Aus cppreference.com

<metanoindex/>

<tbody> </tbody>

definiert in Header

<iterator>

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

Schritten angegeben Iterator it durch n Elementen .

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.

Wenn n negativ ist, wird der Iterator dekrementiert. In diesem Fall InputIt müssen den Anforderungen der BidirectionalIterator gerecht zu werden, da sonst das Verhalten undefiniert ist .

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.

Parameter

it -

iterator vorangetrieben werden

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 -

Anzahl der Elemente it sollte vorangetrieben werden

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.

Rückgabewert

(None)

Original:

(none)

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

Komplexität

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.

Wenn jedoch zusätzlich InputIt erfüllt die Anforderungen der RandomAccessIterator ist Komplexität konstanten .

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.

Beispiel

#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';
}

Output:

Siehe auch

gibt den Abstand zwischen zwei Iterationen

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.


(Funktion) [edit]