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

La description

La fonction C ++ std::forward_list::operator< teste si first forward_list est inférieur à other 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 à 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 std :: forward_list :: operator <function.

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {

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

   if (fl1 < fl2)
      cout << "First list is less than second." << endl;

   fl1.push_front(5);
   fl1.push_front(6);
   fl1.push_front(7);

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

   return 0;
}

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

First list is less than second.
First list is not less than second.