Libreria stack C ++ - funzione stack ()
Descrizione
Il costruttore di mosse C ++ std::stack::stack() costruisce lo stack con il contenuto di altri utilizzando la semantica di spostamento.
Dichiarazione
Di seguito è riportata la dichiarazione per il costruttore std :: stack :: stack () nella forma std :: stack header.
C ++ 11
template <class Alloc>
stack (stack&& x, const Alloc& alloc); 
    Parametri
x - Stack oggetto dello stesso tipo.
alloc - Oggetto allocatore.
Valore di ritorno
Il costruttore non restituisce mai valori.
Eccezioni
Questa funzione membro non genera mai eccezioni.
Complessità temporale
Lineare cioè O (n)
Esempio
L'esempio seguente mostra l'utilizzo del costruttore std :: stack :: stack ().
#include <iostream>
#include <stack>
using namespace std;
int main(void) {   
   stack<int> s1;
   for (int i = 0; i < 5; ++i)
      s1.push(i + 1);
   cout << "Size of stack s1 before move operation = " << s1.size() << endl;
   stack<int> s2(move(s1));
   cout << "Size of stack s1 after move operation = " << s1.size() << endl;
   cout << "Contents of stack s2" << endl;
   while (!s2.empty()) {
      cout << s2.top() << endl;
      s2.pop();
   }
   return 0;
} 
    Compiliamo ed eseguiamo il programma sopra, questo produrrà il seguente risultato:
Size of stack s1 before move operation = 5
Size of stack s1 after move operation = 0
Contents of stack s2
5
4
3
2
1 
                        