home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
INTKYSET
/
DEMOELEM.H
< prev
next >
Wrap
Text File
|
1995-03-15
|
2KB
|
87 lines
/*************************************************************************
IBM C/C++ Tools Version 3.00 - Collection Class Library
(C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
IBM. All Rights Reserved. US Government Users Restricted Rights - Use,
duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM Corp.
*************************************************************************/
/*-------------------------------------------------------------*\
| demoelem.h - DemoElement for use with Key Collections |
\*-------------------------------------------------------------*/
#ifndef _DEMOELEM_H
#define _DEMOELEM_H
#include <stdlib.h>
#include <iglobals.h>
#include <iostream.h>
#include <istdops.h>
class DemoElement {
int i;
int j;
public:
DemoElement ()
: i(0), j(0)
{
}
DemoElement (int i,int j)
: i (i), j(j)
{
}
operator int () const
{ return i;
}
IBoolean operator == (DemoElement const& k) const
{ return i == k.i && j == k.j;
}
IBoolean operator < (DemoElement const& k) const
{ return i < k.i || (i == k.i && j < k.j);
}
friend unsigned long
hash (DemoElement const& k, unsigned long n)
{ return k.i % n;
}
int const &
geti () const
{ return i;
}
int const &
getj () const
{ return j;
}
};
inline ostream & operator << (ostream &sout, DemoElement const& e)
{ sout << e.geti () << "," << e.getj ();
return sout;
}
inline int const& key (DemoElement const& k)
{ return k.geti ();
}
// NOTE: You must return a const & in the key function!
// Otherwise the implicitly created standard element operations
// will return a reference to a temporary. This would lead to
// incorrect behavior of the collection operations.
// The key function must be declared in the header file of
// the collection's element type.
// If either of this is not possible or undesirable,
// an element operations class must be used.
#endif