// Common, group Miscelaneous
// Copyright Alexander Liss
#ifndef __SMALLTEMP_H__
#define __SMALLTEMP_H__
// if compare is defined and returns -1,0,1,
// then all operations are defined
// if compare returns other than -1,0,1,
// then operations return false, as should be
template<class T>
bool operator==(const T& z1,const T& z2)
{return compare(z1,z2)==0;}
template<class T>
bool operator<(const T& z1,const T& z2)
{return compare(z1,z2)==1;}
// define only == and < , the rest automatically
// as in STL - namespace std::rel_ops
template<class T>
bool operator!=(const T& n1,const T& n2)
{return !(n1==n2);}
template<class T>
bool operator<=(const T& n1,const T& n2)
{return n1==n2 || n1<n2;}
template<class T>
bool operator>(const T& n1,const T& n2)
{return !(n1<=n2);}
template<class T>
bool operator>=(const T& n1,const T& n2)
{return n1==n2 || n1>n2;}
////
template<class T>
T& RefMax(const T& z1,const T& z2)
{
if(z1>=z2) return z1;
return z2;
}
template<class T>
T& RefMin(const T& z1,const T& z2)
{
if(z1<=z2) return z1;
return z2;
}
// class T needs default constructor,
// but does not assume copy constructor or assignment operator
// no checking - a simple tool
template<class T>
class Array
{
Array(const Array&);
Array& operator=(const Array&);
public:
Array(int n=0):data(0),allocated(n)
{ if(n>0) data=new T[n]; }
~Array(){delete[] data;}
int size()const{return allocated;}
T& operator[](int i){return data[i];}
protected:
int allocated;
T *data;
};
////
// autopointer
template<class T>
class PointerMaster
{
T* t;
PointerMaster(const PointerMaster&);
PointerMaster& operator=(const PointerMaster&);
public:
PointerMaster(T* tt):t(tt){}
~PointerMaster(){delete t;}
T& operator *()const{return *t;}
T* operator ->()const{return t;}
};
#endif