Go to the first, previous, next, last section, table of contents.


Qstl.h: quantifiers for STL containers.

The Standard Template Library (STL) is a library for C++ that makes extensive use of templates to implement the standard container classes and much more. Each of the container classes provides an interface to iterate over all the objects in the container, e.g.

// MAP is an associate array from location(lat,long) onto the name.
typedef map<location,string,locationlt> MAP;

void print_map_names(MAP& m) { // print out all the names in the map
  for(MAP::iterator i = m.begin(); i != m.end(); ++i) {
    cout << (*i).second << "\n";
  }
}

`Qstl.h' provides the same facilities as `Q.h' but uses the standard STL iterator protocol shown above. The names in `Qstl.h' are generated by appending a `O' (O not zero!) to the names in `Q.h'. In particular:

Macro: bool AO (name,container,predicate)
For all values in the container class the predicate must be true. The predicate refers to individual values using name. See the STL documentation for more details. Another way of putting this is forall name in container the predicate must be true.

  map<int,char *,ltint> m;
  // all keys (or indexes) into m are positive	
  I(AO(i, m, (*i).first >= 0)); 

Macro: bool EO (name,container,predicate)
There exists one or more values in the container class for which the predicate is true.

  map<int,char,ltint> m;

  // one or more characters in m are '$'
  I(EO(i, m, (*i).second == '$')); 

Macro: bool E1O (name,container,predicate)
There exists one value in the container for which the predicate is true.

  map<int,char,ltint> m;

  // one characters in m is a '$'
  I(E1O(i, m, (*i).second == '$')); 

Macro: int CO (name,container,predicate)
Returns the number of times the predicate was true for all values in the container.

  map<int,char,ltint> m;
  int nalpha; 
  // count the number of alphabetic chars in the map
  nalpha = CO(i, m, isalpha((*i).second)); 

Macro: typeof(exprn) SO (name,container,exprn)
Sum the exprn for all values in the container.

  map<int,float,ltint> m;
  float sum;
  // sum all the values in m
  sum = SO(i, m, (*i).second); 

Macro: typeof(exprn) PO (name,container,exprn)
Take the product of the exprn for all values in the container.

  map<int,float,ltint> m;
  float product;
  // multiply all the values in m
  product = PO(i, m, (*i).second); 


Go to the first, previous, next, last section, table of contents.