Operator <set>

operator!= (set)

Pengujian jika objek yang diatur di sisi kiri operator tidak sama dengan objek yang diatur di sisi kanan.

bool operator!=(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis set.

right
Objek jenis set.

Tampilkan Nilai

true jika set tidak sama; false jika set sama.

Keterangan

Perbandingan antara objek yang ditetapkan didasarkan pada perbandingan berpasangan antara elemennya. Dua set sama jika memiliki jumlah elemen yang sama dan elemennya masing-masing memiliki nilai yang sama. Jika tidak, mereka tidak sama.

Contoh

// set_op_ne.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

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

   if ( s1 != s3 )
      cout << "The sets s1 and s3 are not equal." << endl;
   else
      cout << "The sets s1 and s3 are equal." << endl;
}
/* Output:
The sets s1 and s2 are not equal.
The sets s1 and s3 are equal.
*/

operator< (set)

Menguji apakah objek yang diatur di sisi kiri operator kurang dari objek yang diatur di sisi kanan.

bool operator<(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis set.

right
Objek jenis set.

Tampilkan Nilai

true jika set di sisi kiri operator benar-benar kurang dari yang diatur di sisi kanan operator; jika tidak false.

Keterangan

Perbandingan antara objek yang ditetapkan didasarkan pada perbandingan berpasangan dari elemennya. Hubungan kurang dari dua objek didasarkan pada perbandingan pasangan pertama elemen yang tidak sama.

Contoh

// set_op_lt.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 < s2 )
      cout << "The set s1 is less than the set s2." << endl;
   else
      cout << "The set s1 is not less than the set s2." << endl;

   if ( s1 < s3 )
      cout << "The set s1 is less than the set s3." << endl;
   else
      cout << "The set s1 is not less than the set s3." << endl;
}
/* Output:
The set s1 is less than the set s2.
The set s1 is not less than the set s3.
*/

operator<= (set)

Pengujian apakah objek yang diatur di sisi kiri operator kurang dari atau sama dengan objek yang diatur di sisi kanan.

bool operator!<=(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis set.

right
Objek jenis set.

Tampilkan Nilai

true jika set di sisi kiri operator kurang dari atau sama dengan set di sisi kanan operator; jika tidak false.

Keterangan

Perbandingan antara objek yang ditetapkan didasarkan pada perbandingan berpasangan dari elemennya. Hubungan yang kurang dari atau sama dengan dua objek didasarkan pada perbandingan pasangan pertama elemen yang tidak sama.

Contoh

// set_op_le.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 <= s2 )
      cout << "Set s1 is less than or equal to the set s2." << endl;
   else
      cout << "The set s1 is greater than the set s2." << endl;

   if ( s1 <= s3 )
      cout << "Set s1 is less than or equal to the set s3." << endl;
   else
      cout << "The set s1 is greater than the set s3." << endl;

   if ( s1 <= s4 )
      cout << "Set s1 is less than or equal to the set s4." << endl;
   else
      cout << "The set s1 is greater than the set s4." << endl;
}
Set s1 is less than or equal to the set s2.
The set s1 is greater than the set s3.
Set s1 is less than or equal to the set s4.

operator== (set)

Pengujian jika objek yang diatur di sisi kiri operator sama dengan objek yang diatur di sisi kanan.

bool operator!==(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis set.

right
Objek jenis set.

Tampilkan Nilai

true jika set di sisi kiri operator sama dengan set di sisi kanan operator; jika tidak false.

Keterangan

Perbandingan antara objek yang ditetapkan didasarkan pada perbandingan berpasangan dari elemennya. Dua set sama jika memiliki jumlah elemen yang sama dan elemennya masing-masing memiliki nilai yang sama. Jika tidak, mereka tidak sama.

Contoh

// set_op_eq.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

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

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

operator> (set)

Menguji apakah objek yang diatur di sisi kiri operator lebih besar dari objek yang diatur di sisi kanan.

bool operator>(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis set.

right
Objek jenis set.

Tampilkan Nilai

true jika set di sisi kiri operator lebih besar dari yang diatur di sisi kanan operator; jika tidak false.

Keterangan

Perbandingan antara objek yang ditetapkan didasarkan pada perbandingan berpasangan dari elemennya. Hubungan yang lebih besar dari dua objek didasarkan pada perbandingan pasangan pertama elemen yang tidak sama.

Contoh

// set_op_gt.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 > s2 )
      cout << "The set s1 is greater than the set s2." << endl;
   else
      cout << "The set s1 is not greater than the set s2." << endl;

   if ( s1 > s3 )
      cout << "The set s1 is greater than the set s3." << endl;
   else
      cout << "The set s1 is not greater than the set s3." << endl;
}
/* Output:
The set s1 is not greater than the set s2.
The set s1 is greater than the set s3.
*/

operator>= (set)

Menguji apakah objek yang diatur di sisi kiri operator lebih besar dari atau sama dengan objek yang diatur di sisi kanan.

bool operator!>=(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis set.

right
Objek jenis set.

Tampilkan Nilai

true jika set di sisi kiri operator lebih besar dari atau sama dengan set di sisi kanan daftar; jika tidak false.

Keterangan

Perbandingan antara objek yang ditetapkan didasarkan pada perbandingan berpasangan dari elemennya. Lebih besar dari atau sama dengan hubungan antara dua objek didasarkan pada perbandingan pasangan pertama elemen yang tidak sama.

Contoh

// set_op_ge.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 >= s2 )
      cout << "Set s1 is greater than or equal to set s2." << endl;
   else
      cout << "The set s1 is less than the set s2." << endl;

   if ( s1 >= s3 )
      cout << "Set s1 is greater than or equal to set s3." << endl;
   else
      cout << "The set s1 is less than the set s3." << endl;

   if ( s1 >= s4 )
      cout << "Set s1 is greater than or equal to set s4." << endl;
   else
      cout << "The set s1 is less than the set s4." << endl;
}
The set s1 is less than the set s2.
Set s1 is greater than or equal to set s3.
Set s1 is greater than or equal to set s4.

operator!= (multiset)

Menguji apakah objek multiset di sisi kiri operator tidak sama dengan objek multiset di sisi kanan.

bool operator!=(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis multiset.

right
Objek jenis multiset.

Tampilkan Nilai

true jika set atau multiset tidak sama; false jika set atau multiset sama.

Keterangan

Perbandingan antara objek multiset didasarkan pada perbandingan berpasangan antara elemennya. Dua set atau multiset sama jika memiliki jumlah elemen yang sama dan elemennya masing-masing memiliki nilai yang sama. Jika tidak, mereka tidak sama.

Contoh

// multiset_op_ne.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

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

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

operator< (multiset)

Menguji apakah objek multiset di sisi kiri operator kurang dari objek multiset di sisi kanan.

bool operator<(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis multiset.

right
Objek jenis multiset.

Tampilkan Nilai

true jika multiset di sisi kiri operator benar-benar kurang dari multiset di sisi kanan operator; jika tidak false.

Keterangan

Perbandingan antara objek multiset didasarkan pada perbandingan berpasangan dari elemennya. Hubungan kurang dari dua objek didasarkan pada perbandingan pasangan pertama elemen yang tidak sama.

Contoh

// multiset_op_lt.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 < s2 )
      cout << "The multiset s1 is less than "
           << "the multiset s2." << endl;
   else
      cout << "The multiset s1 is not less than "
           << "the multiset s2." << endl;

   if ( s1 < s3 )
      cout << "The multiset s1 is less than "
           << "the multiset s3." << endl;
   else
      cout << "The multiset s1 is not less than "
           << "the multiset s3." << endl;
}
The multiset s1 is less than the multiset s2.
The multiset s1 is not less than the multiset s3.

operator<= (multiset)

Menguji apakah objek multiset di sisi kiri operator kurang dari atau sama dengan objek multiset di sisi kanan.

bool operator!<=(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis multiset.

right
Objek jenis multiset.

Tampilkan Nilai

true jika multiset di sisi kiri operator kurang dari atau sama dengan multiset di sisi kanan operator; jika tidak false.

Keterangan

Perbandingan antara objek multiset didasarkan pada perbandingan berpasangan dari elemennya. Hubungan yang kurang dari atau sama dengan dua objek didasarkan pada perbandingan pasangan pertama elemen yang tidak sama.

Contoh

// multiset_op_le.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 <= s2 )
      cout << "The multiset s1 is less than "
           << "or equal to the multiset s2." << endl;
   else
      cout << "The multiset s1 is greater than "
           << "the multiset s2." << endl;

   if ( s1 <= s3 )
      cout << "The multiset s1 is less than "
           << "or equal to the multiset s3." << endl;
   else
      cout << "The multiset s1 is greater than "
           << "the multiset s3." << endl;

   if ( s1 <= s4 )
      cout << "The multiset s1 is less than "
           << "or equal to the multiset s4." << endl;
   else
      cout << "The multiset s1 is greater than "
           << "the multiset s4." << endl;
}
The multiset s1 is less than or equal to the multiset s2.
The multiset s1 is greater than the multiset s3.
The multiset s1 is less than or equal to the multiset s4.

operator== (multiset)

Menguji apakah objek multiset di sisi kiri operator sama dengan objek multiset di sisi kanan.

bool operator!==(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis multiset.

right
Objek jenis multiset.

Tampilkan Nilai

true jika multiset di sisi kiri operator sama dengan multiset di sisi kanan operator; jika tidak false.

Keterangan

Perbandingan antara objek multiset didasarkan pada perbandingan berpasangan dari elemennya. Dua set atau multiset sama jika memiliki jumlah elemen yang sama dan elemennya masing-masing memiliki nilai yang sama. Jika tidak, mereka tidak sama.

Contoh

// multiset_op_eq.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

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

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

operator> (multiset)

Menguji apakah objek multiset di sisi kiri operator lebih besar dari objek multiset di sisi kanan.

bool operator>(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis multiset.

right
Objek jenis multiset.

Tampilkan Nilai

true jika multiset di sisi kiri operator lebih besar dari multiset di sisi kanan operator; jika tidak false.

Keterangan

Perbandingan antara objek multiset didasarkan pada perbandingan berpasangan dari elemennya. Hubungan yang lebih besar dari dua objek didasarkan pada perbandingan pasangan pertama elemen yang tidak sama.

Contoh

// multiset_op_gt.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 > s2 )
      cout << "The multiset s1 is greater than "
           << "the multiset s2." << endl;
   else
      cout << "The multiset s1 is not greater "
           << "than the multiset s2." << endl;

   if ( s1 > s3 )
      cout << "The multiset s1 is greater than "
           << "the multiset s3." << endl;
   else
      cout << "The multiset s1 is not greater than "
           << "the multiset s3." << endl;
}
The multiset s1 is not greater than the multiset s2.
The multiset s1 is greater than the multiset s3.

operator>= (multiset)

Menguji apakah objek multiset di sisi kiri operator lebih besar dari atau sama dengan objek multiset di sisi kanan.

bool operator!>=(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parameter

left
Objek jenis multiset.

right
Objek jenis multiset.

Tampilkan Nilai

true jika multiset di sisi kiri operator lebih besar dari atau sama dengan multiset di sisi kanan daftar; jika tidak false.

Keterangan

Perbandingan antara objek multiset didasarkan pada perbandingan berpasangan dari elemennya. Lebih besar dari atau sama dengan hubungan antara dua objek didasarkan pada perbandingan pasangan pertama elemen yang tidak sama.

Contoh

// multiset_op_ge.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 >= s2 )
      cout << "The multiset s1 is greater than "
           << "or equal to the multiset s2." << endl;
   else
      cout << "The multiset s1 is less than "
           << "the multiset s2." << endl;

   if ( s1 >= s3 )
      cout << "The multiset s1 is greater than "
           << "or equal to the multiset s3." << endl;
   else
      cout << "The multiset s1 is less than "
           << "the multiset s3." << endl;

   if ( s1 >= s4 )
      cout << "The multiset s1 is greater than "
           << "or equal to the multiset s4." << endl;
   else
      cout << "The multiset s1 is less than "
           << "the multiset s4." << endl;
}
The multiset s1 is less than the multiset s2.
The multiset s1 is greater than or equal to the multiset s3.
The multiset s1 is greater than or equal to the multiset s4.