array


template <class T>
class array : public Semaphore
{
 public:

  typedef arrayIterator<T> iterator;

  typedef constArrayIterator<T> const_iterator;

  array();

  array(const array<T>& copy);

  template<class I>
  array(I first,I last);

  ~array();

  array<T>& operator=(const array<T>& copy);

  void* operator new(size_t s);

  void operator delete(void* p);

  iterator after(Unsigned Key) const;

  iterator afterEquals(Unsigned Key) const;

  iterator before(Unsigned Key) const;

  iterator beforeEquals(Unsigned Key) const;

  iterator begin();

  const_iterator begin() const;

  Unsigned depth() const; 

  iterator end();

  const_iterator end() const;

  void erase();

  void erase(Unsigned Key);

  bool exists(Unsigned Key) const;

  iterator find(Unsigned Key) const;

  iterator insert(const T& Data);

  iterator insert(Unsigned Key, const T& Data);

  iterator last();

  const_iterator last() const;

  Unsigned length() const;

  const T& operator[](Unsigned Key) const;

  class reference
  {
   public:

   reference(array<T>& ArraySet, Unsigned KeySet)
    : Array(&ArraySet), Key(KeySet)  {}

   reference& operator=(const T& Value)
   {
    Array->insert(Key,Value);
    return *this;
   }

   reference& operator=(const reference& Reference)
   {
    Array->insert(Key,(T&)Reference);
    return *this;
   }

   operator T&() const
   {
    iterator i = Array->find(Key);
    return i.value();
   }

   array<T>* Array;
   Unsigned Key;
  };

  reference operator[](Unsigned Key) {return reference(*this, Key);}

  array<T>& operator>>(Unsigned key);

  void sort(int (*Compare)(const T&,const T&)=compare);
};