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

La description

La fonction C ++ std::forward_list::operator<= teste si la première forward_list est inférieure ou égale à autre ou non.

Déclaration

Voici la déclaration de l'en-tête std :: forward_list :: operator <= function form 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 inférieure ou égale à la seconde sinon false.

Des exceptions

Cette fonction ne lève jamais d'exception.

Complexité temporelle

Linéaire ie O (n)

Exemple

L'exemple suivant montre l'utilisation de std :: forward_list :: operator <= function.

#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 << "First list is less than or equal to second." << endl;

   fl1.push_front(6);

   if (!(fl1 <= fl2))
      cout << "First list is not less than or equal to second." << endl;

   return 0;
}

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

First list is less than or equal to second.
First list is not less than or equal to second.