home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
SAMPLES
/
ICLCC
/
DEMOELEM.H
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-07
|
3KB
|
60 lines
/******************************************************************************/
/* */
/* COPYRIGHT: */
/* ---------- */
/* Copyright (C) International Business Machines Corp., 1991,1992. */
/* */
/* DISCLAIMER OF WARRANTIES: */
/* ------------------------- */
/* The following [enclosed] code is sample code created by IBM */
/* Corporation. This sample code is not part of any standard IBM product */
/* and is provided to you solely for the purpose of assisting you in the */
/* development of your applications. The code is provided "AS IS", */
/* without warranty of any kind. IBM shall not be liable for any damages */
/* arising out of your use of the sample code, even if they have been */
/* advised of the possibility of such damages. */
/* */
/******************************************************************************/
/*-------------------------------------------------------------*\
| 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;}
Boolean operator == (DemoElement const& k) const
{ return i == k.i && j == k.j; }
Boolean 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;
}
// NOTE: You MUST return a const & in the key function
// otherwise you are returning a reference to a temporary
inline int const& key (DemoElement const& k) {return k.geti();}
#endif