In the beginning was FORTRAN; Science created FORTRAN and loved it and saw that it was good. Many great and mighty works were done in this language as it spread across the face of the deep. This --- the favored language, imbued with the power of transformation --- understood the very mind of Science.

But, lo! there was another language stirring in the garden. It was called "C" and employed the dark arts and pointer arithmetic. Lacking a native complex type and at least six extra letters in its name, C became jealous of FORTRAN, the beloved. With it's spawn, C++, it struck out to win the heart of Science.

Now, in those days, before the Standard Template Library enslaved the mind of man, it was common for the Fallen to write an Array class, which C++ lacked. These dark souls, forsaken by their peers, began the tedious job of porting Scientific code into the forbidden language. In their zeal, they abused interfaces and idioms, releasing abominations upon the Earth. Take, for example, the following code, sent in by one of the Priests of the Dark Order, who is in deep contemplation of the classes that glue the ancient ways to standard templates.

template<class T> class Array : public Base
public: /* ... */

class CIterSTL
: thePos(0) {}
CIterSTL (const Array<T>&);

void operator++()
void operator++(int)
{ this->operator++(); }

bool operator== (const T* const pos) const
{ return thePos == pos; }

bool operator!= (const T* const pos) const
{ return thePos != pos; }

bool operator== (const ConstIteratorSTL& other) const
{ return thePos == other.thePos; }

bool operator!= (const ConstIteratorSTL& other) const
{ return thePos != other.thePos; }

const T& operator*() const
{ return *thePos; }

const T* thePos;

class IterSTL: public CIterSTL
: CIterSTL () {}
IterSTL (Array<T>& arr)
: CIterSTL (arr) {}
T& operator*()
{ return *const_cast<T*>(CIterSTL::thePos); }

bool operator== (const T* const position) const
{ return CIterSTL::thePos == position; }

bool operator!= (const T* const position) const
{ return ConstIteratorSTL::thePos != position; }

bool operator== (const IterSTL& other) const
{ return CIterSTL::thePos == other.CIterSTL::thePos; }

bool operator!= (const IterSTL& other) const
{ return CIterSTL::thePos != other.CIterSTL::thePos; }

// STL-style iterators.
// Array<Int> array(s);
// for ( Array<Int>::iterator iter = array.begin(); iter != array.end(); iter++ ) {
// *iter += 1;
// }

typedef T type;
typedef IterSTL iterator;
typedef CIterSTL const_iterator;
typedef const T* const end_iterator;

iterator begin()
{ return iterator (*this); }
const_iterator begin() const
{ return const_iterator (*this); }
const T* const end() const
{ return end_p; }

T* end_p;
void setEndP()
{ end_p = /* magic */ }

Normally we'd reveal the unholy abbot's secrets here, at the end; but this article is of a different type than most begin. Not that you'd be able to use any standard algorithms to figure it out, as the iterators work only as described in the innermost code snippet.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!