In the following code..

Any template or design 'gotchas' ?

Suggest

1.More concise versions of the member functions.

2.Boundary conditions I may have missed.

3.A way to provide a better interface. I thought about making everything in node private and make list a friend... but it makes the interface more convoluted.

4.Anything else I have messed up...or could be done better.

Code:namespace mm { template<typename T> class node { public: T val; node<T>* next; node<T>* prev; node<T>() { next = 0; prev = 0; } node<T>(T n, node<T>* nxt=new node<T>(), node<T>* prv=new node<T>()) { val = n; next = nxt; prev = prv; } bool null_p() { return (next==0)||(prev==0); } }; template<typename T> void link(node<T>* x, node<T>* y) { x->next = y; y->prev = x; } template<typename T> class list { int size_val; node<T>* ini; node<T>* fin; public: node<T>* begin(){return ini;}; node<T>* end(){return fin->next;}; int size(){return size_val;} list() { ini =new node<T>(); fin =new node<T>(); size_val = 0; } void append(T n) { size_val++; node<T>* newbie = new node<T>(n); if(ini->null_p()&&fin->null_p()) { link(ini,newbie); link(newbie,fin); ini=fin = newbie; } else { link(newbie,fin->next); link(fin,newbie); fin = newbie; } } void insert(T n, node<T>* ref)// Insert a node containing n AFTER ref { size_val++; node<T>* newbie = new node<T>(n); link(newbie,ref->next); link(ref,newbie); if(ref==fin)fin = fin->next; } void remove(node<T>* ref) { if(size_val==0)return; if(size_val==1) { ini = ini->prev; fin = fin->next; ini->next = 0; fin->prev = 0; delete ref; } else { link(ref->prev,ref->next); if(ref == ini)ini=ref->next; if(ref == fin)fin=ref->prev; delete ref; } size_val--; } void debug_print() { if(size_val!=0) for(node<T>* x = begin();x!=end();x = x->next ) std::cout<<"< "<<x->val<<'\t'<<!x->null_p()<<" >\n"; std::cout<<"Total- "<< size_val<<std::endl; } }; }