Aracılığıyla paylaş


deque::operator== ve deque::operator<

Nasıl kullanılacağı gösterilmiştir deque::operator == ve deque::operator < Visual C++ standart şablon kitaplığı (stl) işlevleri.

template<class T, class A>
   bool operator==(
      const deque <T, A>& Left,
      const deque <T, A>& Right
   );
template<class T, class A>
   bool operator<(
      const deque <T, A>& Left,
      const deque <T, A>& Right
   );

Notlar

[!NOT]

Prototip sınıfı/parametre adları üstbilgi dosyasında sürüm eşleşmiyor.Bazıları, okumayı kolaylaştırmak için değiştirildi.

İlk şablon işlevi aşırı operator== iki şablon sınıfı deque nesnelerin Karşılaştırılacak.İşlev verir sol.size == Right. boyutu & & equal(Left.başlamak, Left.end, Right.begin).Eşitlik için öğelerin sayısını iki deque nesneleri eşit olmalıdır.İkinci şablon işlevi aşırı operator < iki şablon sınıfı deque nesnelerin Karşılaştırılacak.İşlev verir: lexicographical_compare(sol.başlamak, Left.end, Right.begin, Right.end).Çünkü lexicographical_compare olan kullanıldığında, ELEMAN kullanırken önemli değildir operator <.Örnek kodda bir kod satırı oluşturulurken ekleme b nesne, b.push_front('D');, will make b greater than a.

Örnek

// deque_operators.cpp
// compile with: /EHsc
//
// Functions:
//    ==
//    <

#include <iostream>
#include <deque>

using namespace std;

typedef deque<char >  CHARDEQUE;
void print_contents (CHARDEQUE  deque, char*);

int main()
{
    //create a  with  3 A's
    CHARDEQUE  a(3,'A');
    a.push_front('C');

    //create b with 4 B's.
    CHARDEQUE  b(6,'B');

    //print out the contents
    print_contents (a,"a");
    print_contents (b,"b");

    //compare a and b
    if (a==b)
        cout <<"a is equal to b"<<endl;
    else if(a<b)
            cout <<"a is less than b"<<endl;
    else
        cout <<"a is greater than b" <<endl;

    //assign the contents of b to a
    a.assign(b.begin(),b.end());
    print_contents (a,"a");
    print_contents (b,"b");

    //compare a and b again
    if (a==b)
        cout <<"a is equal to b"<<endl;
    else if(a<b)
            cout <<"a is less than b"<<endl;
    else
        cout <<"a is greater than b" <<endl;

}

//function to print the contents of deque
void print_contents (CHARDEQUE  deque, char *name)
{
    CHARDEQUE::iterator pdeque;

    cout <<"The contents of "<< name <<" : ";

        for(pdeque = deque.begin();
        pdeque != deque.end();
        pdeque++)
    {
        cout << *pdeque <<" " ;
    }
        cout<<endl;
}

Çıktı

The contents of a : C A A A 
The contents of b : B B B B B B 
a is greater than b
The contents of a : B B B B B B 
The contents of b : B B B B B B 
a is equal to b

Gereksinimler

Başlık: <deque>

Ayrıca bkz.

Kavramlar

Standart şablon kitaplığı örnekleri