template <class KeyType, class ValueType>
class Map
{
public:
// Return true if empty.
bool isEmpty( ) const;
// Return the number of keys currently
stored.
int getSize( ) const;
// Return a vector that contains
all the keys.
vector<KeyType> getAllKeys( ) const;
// Make the map empty.
void makeEmpty( );
// Add a key and value; if key already
present, override value.
void insert( const KeyType & key, const
ValueType & val );
// Remove a key and its associated
value if found; otherwise, do nothing.
void remove( const KeyType & key );
// Get the value corresponding to
key (see below).
ValueType & operator[] ( const KeyType &
key );
const ValueType & operator[] ( const KeyType
& key ) const;
private:
struct Pair
{
KeyType
key;
ValueType value;
Pair( const KeyType &
k = KeyType( ), const ValueType & v = ValueType( ) )
: key( k
), value( v ) { }
};
vector<Pair> items;
};