#ifndef BLOCK_H
#define BLOCK_H

template<class T>
class Block	{
public:
	unsigned size() const { return n; }
	unsigned size(unsigned);
	Block() { n = 0; p = 0; }
	Block(unsigned k) { n = 0; p = 0; size(k); }
	Block(const Block<T>& b) { copy(b); }
	~Block();
	Block<T>& operator=(const Block<T>&);
	operator T*() { return p; }
	operator const T*() const { return p; }
	T* end() { return p + n; }
	const T* end() const { return p + n; }
	T& operator[](int i) { check(i); return p[i]; }
	const T& operator[](int i) const { check(i); return p[i]; }
	int reserve(unsigned k) { return k<n || grow(k); }
	void swap(Block<T>& b);
private:
	void check(int i) const ;
	T* p;
	unsigned n;
	void move(T*, unsigned);
	void transfer(T*, unsigned);
	void clear(T*, unsigned);
	void copy(const Block<T>&);
	unsigned grow(unsigned);
	static T* default_value();
};
#endif
