共用方式為


<list> 運算子

operator!=

測試運算子左邊的清單物件是否不等於右邊的清單物件。

bool operator!=(
    const list<Type, Allocator>& left,
    const list<Type, Allocator>& right);

參數

left
list 類型的物件。

right
list 類型的物件。

傳回值

true 如果清單不相等則為 ; false 如果清單相等,則為 。

備註

list 物件之間的比較是以其元素的成對比較為基礎。 如果有相同數目的元素,且個別元素擁有相同的值,則兩個清單相等。 反之則為不相等。

範例

// list_op_ne.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( )
{
using namespace std;
list <int> c1, c2;
c1.push_back( 1 );
c2.push_back( 2 );

if ( c1 != c2 )
cout << "Lists not equal." << endl;
else
cout << "Lists equal." << endl;
}
/* Output:
Lists not equal.
*/

operator<

測試運算子左邊的清單物件是否小於右邊的清單物件。

bool operator<(
    const list<Type, Allocator>& left,
    const list<Type, Allocator>& right);

參數

left
list 類型的物件。

right
list 類型的物件。

傳回值

若運算子左邊的清單小於但不等於右邊的清單,即為 true;否則為 false

備註

list 物件之間的比較是以其元素的成對比較為基礎。 兩個物件之間的小於關聯性是根據第一對不相等元素的比較。

範例

// list_op_lt.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( )
{
   using namespace std;
   list <int> c1, c2;
   c1.push_back( 1 );
   c1.push_back( 2 );
   c1.push_back( 4 );

   c2.push_back( 1 );
   c2.push_back( 3 );

   if ( c1 < c2 )
      cout << "List c1 is less than list c2." << endl;
   else
      cout << "List c1 is not less than list c2." << endl;
}
/* Output:
List c1 is less than list c2.
*/

operator<=

測試運算子左邊的清單物件是否小於或等於右邊的清單物件。

bool operator<=(
    const list<Type, Allocator>& left,
    const list<Type, Allocator>& right);

參數

left
list 類型的物件。

right
list 類型的物件。

傳回值

若運算子左邊的清單小於或等於右邊的清單,即為 true;否則為 false

備註

list 物件之間的比較是以其元素的成對比較為基礎。 兩個物件之間的小於或等於關聯性,是根據第一對不相等元素的比較。

範例

// list_op_le.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( )
{
   using namespace std;
   list <int> c1, c2;
   c1.push_back( 1 );
   c1.push_back( 2 );
   c1.push_back( 4 );

   c2.push_back( 1 );
   c2.push_back( 3 );

   if ( c1 <= c2 )
      cout << "List c1 is less than or equal to list c2." << endl;
   else
      cout << "List c1 is greater than list c2." << endl;
}
/* Output:
List c1 is less than or equal to list c2.
*/

operator==

測試運算子左邊的清單物件是否等於右邊的清單物件。

bool operator==(
    const list<Type, Allocator>& left,
    const list<Type, Allocator>& right);

參數

left
list 類型的物件。

right
list 類型的物件。

傳回值

true 如果運算子左邊的清單等於運算子右邊的清單,則為 ;否則 false為 。

備註

list 物件之間的比較是以其元素的成對比較為基礎。 如果有相同數目的元素,且個別元素擁有相同的值,則兩個清單相等。 反之則為不相等。

範例

// list_op_eq.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
int main( )
{
   using namespace std;

   list <int> c1, c2;
   c1.push_back( 1 );
   c2.push_back( 1 );

   if ( c1 == c2 )
      cout << "The lists are equal." << endl;
   else
      cout << "The lists are not equal." << endl;
}
/* Output:
The lists are equal.
*/

operator>

測試運算子左邊的清單物件是否大於右邊的清單物件。

bool operator>(
    const list<Type, Allocator>& left,
    const list<Type, Allocator>& right);

參數

left
list 類型的物件。

right
list 類型的物件。

傳回值

如果運算子左邊的清單大於右邊的清單,即為 true;否則為 false

備註

list 物件之間的比較是以其元素的成對比較為基礎。 兩個物件之間的大於關聯性是根據第一對不相等元素的比較。

範例

// list_op_gt.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
int main( )
{
   using namespace std;
   list <int> c1, c2;
   c1.push_back( 1 );
   c1.push_back( 3 );
   c1.push_back( 1 );

   c2.push_back( 1 );
   c2.push_back( 2 );
   c2.push_back( 2 );

   if ( c1 > c2 )
      cout << "List c1 is greater than list c2." << endl;
   else
      cout << "List c1 is not greater than list c2." << endl;
}
/* Output:
List c1 is greater than list c2.
*/

operator>=

測試運算子左邊的清單物件是否大於或等於右邊的清單物件。

bool operator>=(
    const list<Type, Allocator>& left,
    const list<Type, Allocator>& right);

參數

left
list 類型的物件。

right
list 類型的物件。

傳回值

true 如果運算子左邊的清單大於或等於運算子右邊的清單,則為 ;否則 false為 。

備註

list 物件之間的比較是以其元素的成對比較為基礎。 兩個物件之間的大於或等於關聯性,是根據第一對不相等元素的比較。

範例

// list_op_ge.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( )
{
   using namespace std;
   list <int> c1, c2;
   c1.push_back( 1 );
   c1.push_back( 3 );
   c1.push_back( 1 );

   c2.push_back( 1 );
   c2.push_back( 2 );
   c2.push_back( 2 );

   if ( c1 >= c2 )
      cout << "List c1 is greater than or equal to list c2." << endl;
   else
      cout << "List c1 is less than list c2." << endl;
}
/* Output:
List c1 is greater than or equal to list c2.
*/