Espaces de noms
Variantes
Affichages
Actions

std::move

De cppreference.com
< cpp‎ | algorithm

 
 
Bibliothèque 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 séquence des opérations
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 séquence des opérations
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 opérations 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.
Opérations de tri (sur les gammes triés)
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
Opérations binaires de recherche (sur les gammes triés)
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.
Définir les opérations (sur les gammes triés)
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.
Opérations 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.
Opérations numériques
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.
Bibliothèque 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.
 
Déclaré dans l'en-tête <algorithm>
template< class InputIt, class OutputIt >
OutputIt move( InputIt first, InputIt last, OutputIt d_first );
(depuis C++11)
Déplace les éléments de la [first, last) gamme, à un autre début de la plage à d_first. Après cette opération, les éléments de la gamme déplacé-de contiendront toujours des valeurs valides du type approprié, mais pas nécessairement les mêmes valeurs que avant le déménagement .
Original:
Moves the elements in the range [first, last), to another range beginning at d_first. After this operation the elements in the moved-from range will still contain valid values of the appropriate type, but not necessarily the same values as before the move.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Sommaire

[modifier] Paramètres

first, last -
la plage d'éléments à déplacer
Original:
the range of elements to move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d_first -
le début de la plage de destination. Si d_first est dans [first, last), std::move_backward doit être utilisé à la place de NJ std :: move </ span> .
Original:
the beginning of the destination range. If d_first is within [first, last), std::move_backward must be used instead of NJ std :: move </ span>. </div>
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
</div></div></div></div>
Type requirements
-
InputIt must meet the requirements of InputIterator.
-
OutputIt must meet the requirements of OutputIterator.

[modifier] Retourne la valeur

Itérateur de sortie de l'élément après le dernier élément déplacé (d_first + (last - first))
Original:
Output iterator to the element past the last element moved (d_first + (last - first))
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifier] Complexité

Exactement last - first déplacer les affectations .
Original:
Exactly last - first move assignments.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifier] Mise en œuvre possible

template<class InputIt, class OutputIt>
OutputIt move(InputIt first, InputIt last, 
                    OutputIt d_first)
{
    while (first != last) {
        *d_first++ = std::move(*first++);
    }
    return d_first;
}

[modifier] Exemple

Le code suivant déplace des objets de fil (qui eux-mêmes sont pas copiables) d'un récipient à un autre. </ p>

Original:
<p>The following code moves thread objects (which themselves are not copyable) from one container to another.</p>
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
</div>
{{{1}}}
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <vector>
#include <list>
#include <iterator>
#include <thread>
#include <chrono>

void f(int n)
{
    std::this_thread::sleep_for(std::chrono::seconds(n));
    std::cout << "thread " << n << " ended" << '\n';
}

int main()
{
    std::vector<std::thread> v;
    v.emplace_back(f, 1);
    v.emplace_back(f, 2);
    v.emplace_back(f, 3);
    std::list<std::thread> l;
    // copy() would not compile, because std::thread is noncopyable

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

std :: move </ span>(v.begin(), v.end(), std::back_inserter(l));
    for(auto& t : l) t.join();
}
</div>

Sortie:
Original:
Output:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
thread 1 ended
thread 2 ended
thread 3 ended

[modifier] Voir aussi

se déplace d'une gamme d'éléments vers un nouvel emplacement dans l'ordre inverse
Original:
moves a range of elements to a new location in backwards order
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]

Récupérée de « https://fr.cppreference.com/mwiki/index.php?title=cpp/algorithm/move&oldid=47529 »