Source file: /~heha/ewa/Ofen/prozess.zip/vector.h

#pragma once
// Nachbau von std::vector ohne Allocator, minimalistisch
// hier fest verdrahtet auf C-Funktion realloc()

namespace std{
template<class T> class vector;

// Die Hilfsklasse ist erforderlich, damit der Iterator bei "->" doppelt dereferenziert.
// Ansonsten verhält er sich genauso wie ein Zeiger auf T.
template<class T> class _Vector_iterator {
public:
 typedef _Vector_iterator<T> myt;
 typedef vector<T> myvec;
 typedef T&reference;
 _Vector_iterator(T*p=0){myptr=p;};
 reference operator*() const {return*myptr;}
// T* operator->() const {return (&**this);}	// return pointer to class object
 myt operator++() {return ++myptr;}		// preincrement
 bool operator!=(const myt&rval) const {return myptr!=rval.myptr;}
 T*myptr;
};

template<class T> class vector{
 typedef size_t size_type;
 size_type fill;
 T*data;
 void realloc(size_t n) {
  data=(T*)::realloc(data,(fill=n)*sizeof T);
  if (n && !data) ::RaiseException(0,0,0,0);
 }
public:
 typedef _Vector_iterator<T> iterator;
 typedef T& reference;
 vector(size_t reserve=0):data(0),fill(0) {realloc(fill);}
 ~vector() {realloc(0);}
 iterator begin() const {return iterator(data);}
 iterator end() const {return iterator(data+fill);}
 reference front() {return *data;}
 reference back() {return data[fill-1];}
 void push_back(const T&val) {realloc(fill+1); back()=val;}
 iterator erase(iterator);
 iterator insert(iterator,const T*);
};
}
Detected encoding: ANSI (CP1252)4
Wrong umlauts? - Assume file is ANSI (CP1252) encoded