2001

Grusel++ of the month

Home
Download Source
/******************************************************************************/
/*                                                                            */
/*                                                          FILE: october.cpp */
/*                                                                            */
/*  Bringing some order into a heap of characters with overloaded operators   */
/*  =======================================================================   */
/*                                                                            */
/*  Compiled and tested with Visual C++ V6.0                                  */
/*                                                                            */
/*  V1.00   21-OCT-2001   P. Tellenbach   http://www.heimetli.ch/             */
/*                                                                            */
/******************************************************************************/

#include <iostream>

class Grusel
{
 protected:
   char *text ;
   int   end ;

 public:
   Grusel( char *txt ) : text(txt), end(strlen(txt))
   {
   }

   ~Grusel()
   {
      std::cout << std::endl ;
   }

   bool operator<( int pos )
   {
      return pos + pos + 1 < end ? (*this)[pos + pos + 1] : pos < end ;
   }
  
   bool operator>( int pos )
   {
      return (*this)[(pos << 1) + 2], pos > 0 ;
   }

   bool operator[]( int pos )
   {
      return *this < pos && std::cout.put(text[pos]).good() && *this > pos ;
   }
} ;

int main()
{
   return Grusel( "ol e l!Hlowrd" )[ 0 ] ;
}