home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / INTKYSET / INTKYSET.CPP < prev    next >
Text File  |  1995-03-15  |  2KB  |  57 lines

  1. /*************************************************************************
  2.   IBM C/C++ Tools Version 3.00 - Collection Class Library
  3.  (C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
  4.  IBM.  All Rights Reserved.  US Government Users Restricted Rights - Use,
  5.  duplication or disclosure restricted by GSA ADP Schedule Contract with
  6.  IBM Corp.
  7.  *************************************************************************/
  8.  
  9.  
  10. /*-------------------------------------------------------------*\
  11. |  intkyset.CPP  -  Integer Key Set for demonstration of using  |
  12. |                   a KeySet.                                   |
  13. \*-------------------------------------------------------------*/
  14. #include <iostream.h>
  15. #include <iglobals.h>
  16. #include <icursor.h>
  17.  
  18. #include <ikeyset.h>
  19.                       // Class DemoElement:
  20. #include "demoelem.h"
  21.  
  22. typedef IKeySet < DemoElement,int > TestKeySet;
  23.  
  24. ostream & operator << ( ostream & sout, TestKeySet const & t)
  25. { sout << t.numberOfElements() << " elements are in the set:" << endl;
  26.  
  27.   TestKeySet::Cursor cursor (t);
  28.  
  29.   //  forCursor(c)
  30.   // expands to
  31.   //  for ((c).setToFirst (); (c).isValid (); (c).setToNext ())
  32.  
  33.   forCursor (cursor)
  34.     sout << "   " << cursor.element () << endl;
  35.  
  36.   return sout << endl;
  37. }
  38.  
  39.  
  40. main()
  41. {
  42.   TestKeySet t;
  43.  
  44.   t.add(DemoElement(1,1));
  45.   t.add(DemoElement(2,4711));
  46.   t.add(DemoElement(3,1));
  47.   t.add(DemoElement(4,443));
  48.  
  49.   cout << t;
  50.  
  51.   t.removeElementWithKey (3);
  52.  
  53.   cout << t;
  54.  
  55.   return 0;
  56. }
  57.