Container operators

C++ Reference

Container operators
Syntax:
  #include <deque>
  TYPE& operator[]( size_type index );
  const TYPE& operator[]( size_type index ) const;
  container operator=(const container& c2);
  bool operator==(const container& c1, const container& c2);
  bool operator!=(const container& c1, const container& c2);
  bool operator<(const container& c1, const container& c2);
  bool operator>(const container& c1, const container& c2);
  bool operator<=(const container& c1, const container& c2);
  bool operator>=(const container& c1, const container& c2);

All of the C++ containers can be compared and assigned with the standard comparison operators: ==, !=, <=, >=, <, >, and =. Individual elements of a dequeue can be examined with the [] operator.

Performing a comparison or assigning one dequeue to another takes linear time. The [] operator runs in constant time.

Two `containers` are equal if:

  1. Their size is the same, and
  2. Each member in location i in one dequeue is equal to the the member in location i in the other dequeue.

Comparisons among dequeues are done lexicographically.

For example, the following code uses the [] operator to access all of the elements of a vector:

 vector<int> v( 5, 1 );
 for( int i = 0; i < v.size(); i++ ) {
   cout << "Element " << i << " is " << v[i] << endl;
 }              
Related topics: