[ Web Proxy ]
URL:
Viewing: https://fr.cppreference.com/cpp/algorithm/iota [Back]  [Original]

std::iota cppreference.com
cppreference.com
Espaces de noms
Variantes

std::iota

De cppreference.com
 
 
Bibliothque d'algorithmes
Fonctions
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Non-modification de la squence des oprations
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Modification de la squence des oprations
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Des oprations de partitionnement
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Oprations de tri (sur les gammes tris)
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is_sorted (C++11)
is_sorted_until (C++11)
sort
Oprations binaires de recherche (sur les gammes tris)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Dfinir les oprations (sur les gammes tris)
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Oprations Heap
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Minimum / maximum de fonctionnement
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Oprations numriques
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bibliothque C
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
<tbody>

</tbody> <tbody class="t-dcl-rev ">

</tbody><tbody> </tbody>
Dclar dans l'en-tte <numeric>
template< class ForwardIt, class T > void iota( ForwardIt first, ForwardIt last, T value );
(depuis C++11)
template< class ForwardIt, class T > constexpr void iota( ForwardIt first, ForwardIt last, T value );


Remplis la plage [first, last) avec des valeurs squenciellement croissantes, commenant par value et rptant ensuite ++value.

Opration quivalente:

*(d_first)   = value;
*(d_first+1) = ++value;
*(d_first+2) = ++value;
*(d_first+3) = ++value;
...

Paramtres

first, last - la plage d'lments remplir avec des valeurs squenciellement croissantes commenant par value
value - valeur initiale placer; l'expression ++value doit tre valide

Valeur de retour

(none)

Complexit

Exactement last - first incrmentations et assignations.

Implmentation possible

template<class ForwardIt, class T>
constexpr // depuis C++20
void iota(ForwardIt first, ForwardIt last, T value)
{
    while(first != last) {
        *first++ = value;
        ++value;
    }
}

Notes

La fonction est nomme aprs la fonction entire du language de programmation APL. C'est un des composants STL qui n'ont pas t inclus dans C++98, mais qui ont t par la suite introduits en C++11.

Exemple

L'exemple suivant applique std::shuffle un vecteur d'itrateurs de std::list puisque std::shuffle ne peut pas tre directement appliqu std::list. std::iota est utilis pour remplir les deux conteneurs.

#include <algorithm>
#include <iostream>
#include <list>
#include <numeric>
#include <random>
#include <vector>

int main()
{
    std::list<int> l(10);
    std::iota(l.begin(), l.end(), -4);

    std::vector<std::list<int>::iterator> v(l.size());
    std::iota(v.begin(), v.end(), l.begin());

    std::shuffle(v.begin(), v.end(), std::mt19937{std::random_device{}()});

    std::cout << "Contents of the list: ";
    for(auto n: l) std::cout << n << ' ';
    std::cout << '\n';

    std::cout << "Contents of the list, shuffled: ";
    for(auto i: v) std::cout << *i << ' ';
    std::cout << '\n';
}

Rsultat possible :

Contents of the list: -4 -3 -2 -1 0 1 2 3 4 5
Contents of the list, shuffled: 0 -1 3 4 -4 1 -2 -3 2 5

Voir aussi

attribue un ensemble d'lments d'une certaine valeur
Original:
assigns a range of elements a certain value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction gnrique) [edit]
enregistre le rsultat d'une fonction dans une plage
Original:
saves the result of a function in a range
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction gnrique) [edit]

Web Proxy Viewer  |  New URL  |  Original Page