Bibliothèque C ++ Forward_list - opérateur == Fonction

La description

La fonction C ++ std::forward_list::operator== teste si deux forward_lists sont égales ou non.

Déclaration

Voici la déclaration de l'en-tête std :: forward_list :: operator == function std :: forward_list.

C ++ 11

template <class T, class Alloc>
bool operator== (const forward_list<T,Alloc>& first, const forward_list<T,Alloc>& second);

Paramètres

  • first - Premier objet forward_list.

  • second - Deuxième objet forward_list du même type.

Valeur de retour

Renvoie true si la première forward_list est la même que la seconde sinon false.

Exceptions

Cette fonction membre ne lève jamais d'exception.

Complexité temporelle

Linéaire ie O (n)

Exemple

L'exemple suivant montre l'utilisation de la fonction std :: forward_list :: operator ==.

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {

   forward_list<int> fl1 = {1, 2, 3, 4, 5};
   forward_list<int> fl2 = {1, 2, 3, 4, 5};

   if (fl1 == fl2)
      cout << "Both lists are equal." << endl;

   fl1.pop_front();

   if (!(fl1 == fl2))
      cout << "Both lists are not equal." << endl;

   return 0;
}

Compilons et exécutons le programme ci-dessus, cela produira le résultat suivant -

Both lists are equal.
Both lists are not equal.