#ifndef TSET_H_ #define TSET_H_ #include "myexception.h" #include "memory.h" template class TSet { T* start, *lastElement, *endOfStorage; int elCount, vectorSize; bool absolute; void initPointers(); static std::allocator alloc; public: typedef T* iterator; public: iterator begin() { return start; }; iterator end() { return lastElement; }; ~TSet() { delete [] start; } TSet() : elCount(0), vectorSize(100),absolute(false) { start = static_cast(operator new(vectorSize * sizeof(T))); lastElement = start; endOfStorage = &start[vectorSize]; } TSet(int absoluteSize) : absolute(true), vectorSize(absoluteSize), elCount(0) { start = new T[vectorSize]; lastElement = start; endOfStorage = &start[vectorSize]; } void add(T& x); void remove(T& x); bool isStored(T& x); int size() { return elCount; }; }; template void TSet::add(T& x) { for (iterator it = begin(); it != end(); it++) { if (it == &x) throw myexception("Element already added"); } if(lastElement != endOfStorage) { construct(lastElement,x); } else { T *temp = static_cast(operator new(vectorSize*vectorSize*sizeof(T))); bcopy(start,temp,(vectorSize)*sizeof(T)); /* for (; start != endOfStorage; start++) { start->~T(); //delete start; } */ delete [] (start); start = temp; endOfStorage = &start[vectorSize*vectorSize]; lastElement = &start[vectorSize]; vectorSize *= vectorSize; construct(lastElement,x); } elCount++; lastElement++; } template void construct(T1* p, const T2& value) { new (p) T1(value); } //TSet *blah = new TSet(); #endif /*TSET_H_*/