operator== (<stack>)

Tests, wenn das Stapelobjekt auf der linken Seite des Operators gleich Stapelobjekt auf der rechten Seite ist.

bool operator==(
   const stack <Type, Container>& _Left,
   const stack <Type, Container>& _Right
);

Parameter

  • _Left
    Ein Objekt des Typs stack.

  • _Right
    Ein Objekt des Typs stack.

Rückgabewert

true, wenn die Stapel oder die Stapel gleich sind, false, wenn Stapel oder Stapel nicht gleich sind.

Hinweise

Der Vergleich zwischen Stapelobjekten basiert auf einem paarweisen Vergleich ihrer Elemente.Zwei Stapel sind gleich, wenn sie dieselbe Anzahl von Elementen aufweisen und ihre jeweiligen Elemente die gleichen Werte aufweisen.Andernfalls sind sie ungleich.

Beispiel

// stack_op_eq.cpp
// compile with: /EHsc
#include <stack>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;

   // Declares stacks with vector base containers
   stack <int, vector<int> > s1, s2, s3;

   // The following would have cause an error because stacks with
   // different base containers are not equality comparable
   // stack <int, list<int> > s3;

   s1.push( 1 );
   s2.push( 2 );
   s3.push( 1 );

   if ( s1 == s2 )
      cout << "The stacks s1 and s2 are equal." << endl;
   else
      cout << "The stacks s1 and s2 are not equal." << endl;

   if ( s1 == s3 )
      cout << "The stacks s1 and s3 are equal." << endl;
   else
      cout << "The stacks s1 and s3 are not equal." << endl;
}
  
  

Anforderungen

Header: <stack>

Namespace: std

Siehe auch

Referenz

Standardvorlagenbibliothek