>I think it is a good practice to write a code that behaves exactly like that.
That's hardly a challenge:
Code:
namespace std {
template <typename T, typename C = deque<T> >
class stack {
template <typename U, typename C1>
friend bool operator== ( const stack<U, C1>&, const stack<U, C1>& );
template <typename U, typename C1>
friend bool operator< ( const stack<U, C1>&, const stack<U, C1>& );
public:
typedef C container_type;
typedef typename C::value_type value_type;
typedef typename C::size_type size_type;
typedef typename C::reference reference;
typedef typename C::const_reference const_reference;
public:
explicit stack ( const C& init = C() ): c ( init ){}
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
reference top() { return c.back(); }
const_reference top() const { return c.back(); }
void push ( const value_type& x ) { c.push_back ( x ); }
void pop() { c.pop_back(); }
protected:
C c;
};
template <typename T, typename C>
inline bool operator== ( const stack<T, C>& lhs, const stack<T, C>& rhs )
{
return lhs.c == rhs.c;
}
template <typename T, typename C>
inline bool operator< ( const stack<T, C>& lhs, const stack<T, C>& rhs )
{
return lhs.c < rhs.c;
}
template <typename T, typename C>
inline bool operator!= ( const stack<T, C>& lhs, const stack<T, C>& rhs )
{
return !(lhs == rhs);
}
template <typename T, typename C>
inline bool operator> ( const stack<T, C>& lhs, const stack<T, C>& rhs )
{
return rhs < lhs;
}
template <typename T, typename C>
inline bool operator<= ( const stack<T, C>& lhs, const stack<T, C>& rhs )
{
return !(rhs < lhs);
}
template <typename T, typename C>
inline bool operator>= ( const stack<T, C>& lhs, const stack<T, C>& rhs )
{
return !(lhs < rhs);
}
}
Now a standard deque, that's harder.