DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Associative Arrays in C++ - Map(3C++)

Key and Value Types

There are several restrictions on the key and value types:

In addition to these restrictions, it must be possible to compare keys for sorting purposes. In other words, if k1 and k2 are two keys, k1<k2 must be well-defined. Moreover, when < is applied to two keys, it must be a "strong total order relation". That is, it must have the following properties: Notice that we do not require that k1==k2 or k1>k2 be defined because we can infer k1>k2 from k2<k1 and k1==k2 from !(k1<k2||k2<k1).

The integral types (int, short, char, and long) and the String class all have an appropriate definition for <. The floating-point types are a different matter: some machines support a special floating-point ``not-a-number'' value (NaN) that is neither less than, greater than, or equal to anything else. Using floating-point keys on such a machine invites disaster if a key is ever NaN. Floating-point values cause no trouble.


Next topic: Using a Map
Previous topic: Defining Map Classes

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004