namespace mystl{
template<class T,class Container = deque<T>>
class stack{
public:
typedef Container container_type;
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef typename Container::reference reference;
typedef typename Container::const_reference const_reference;
//静态断言
static_assert(is_same<T,value_type>::value,
"the value type of Container should be same with T");
private:
container_type c_;
public:
stack() = default;
//C++11的特性 加了explicit后就没法用【等于号+initializer_list】 进行 赋值或初始化了
explicit stack(size_type n):c_(n)
{
}
stack(size_type n,const value_type&value):
c_(n,value)
{
}
stack(const Container& c):c_(c)
{
}
//noexcept运算符进行编译时检查,若表达式声明为不抛出任何异常则返回true。
stack& operator=(const stack& rhs){
c_ = rhs.c_;
return *this;
}
~stack() = default;
reference top() {return c_.back();}
bool empty() const noexcept {return c_.empty();}
size_type size() const noexcept {return c_.size();}
void pop(){
return c_.pop_back();
}
void clear(){
while(!empty()) pop();
}
template<class Args,class ...Args2>
void push(Args a,Args2 ... test){
c_.push_back(a);
push(test...);
}
template<class Args>
void push(Args a){
c_.push_back(a);
}
friend bool operator==(const stack& lhs, const stack& rhs) { return lhs.c_ == rhs.c_; }
friend bool operator< (const stack& lhs, const stack& rhs) { return lhs.c_ < rhs.c_; }
};
template <class T, class Container>
bool operator==(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{
return lhs == rhs;
}
template <class T, class Container>
bool operator<(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{
return lhs < rhs;
}
template <class T, class Container>
bool operator!=(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{
return !(lhs == rhs);
}
template <class T, class Container>
bool operator>(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{
return rhs < lhs;
}
template <class T, class Container>
bool operator<=(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{
return !(rhs < lhs);
}
template <class T, class Container>
bool operator>=(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{
return !(lhs < rhs);
}
}