/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* stack.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/12 19:46:30 by apommier #+# #+# */ /* Updated: 2022/11/29 13:15:44 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef STACK_HPP # define STACK_HPP # include "vector.hpp" namespace ft { template > class stack { public: //----------------------------- //---------MEMBER TYPE--------- //----------------------------- typedef std::size_t size_type; typedef T value_type; typedef Container container_type; protected: container_type c; public: //--------------------------------------- //---------COPLIEN FORM FUNCTION--------- //--------------------------------------- explicit stack (const container_type& ctnr = container_type()) : c(ctnr){}//default constructor stack(const stack &other )//copy constructor { *this = other; } ~stack(void) {}//destructor stack &operator=( const stack &other )//assigment operator { if (this != &other) this->c = other.c; return *this; } //---------------------------------- //---------MEMBER FUNCTION---------- //---------------------------------- bool empty() const { return (c.empty()); } size_type size() const { return (c.size()); } value_type& top() { return (c.back()); } const value_type& top() const { return (c.back()); } void push (const value_type& val) { return (c.push_back(val)); } void pop() { return (c.pop_back()); } template friend bool operator==(const ft::stack& lhs, const ft::stack& rhs ); template friend bool operator!=(const ft::stack& lhs, const ft::stack& rhs ); template friend bool operator<(const ft::stack& lhs, const ft::stack& rhs ); template friend bool operator<=(const ft::stack& lhs, const ft::stack& rhs ); template friend bool operator>(const ft::stack& lhs, const ft::stack& rhs ); template friend bool operator>=(const ft::stack& lhs, const ft::stack& rhs ); }; //--------------------------------------------- //---------OPERATOR OVERLOAD FUNCTION---------- //--------------------------------------------- template< class T, class Container > bool operator==(const ft::stack& lhs, const ft::stack& rhs ) { return (lhs.c == rhs.c); } template< class T, class Container > bool operator!=(const ft::stack& lhs, const ft::stack& rhs ) { return (!(lhs.c == rhs.c)); } template< class T, class Container > bool operator<(const ft::stack& lhs, const ft::stack& rhs ) { return (lhs.c < rhs.c); } template< class T, class Container > bool operator<=(const ft::stack& lhs, const ft::stack& rhs ) { return (!(rhs.c < lhs.c)); } template< class T, class Container > bool operator>(const ft::stack& lhs, const ft::stack& rhs ) { return (rhs.c < lhs.c); } template< class T, class Container > bool operator>=(const ft::stack& lhs, const ft::stack& rhs ) { return (!(lhs.c < rhs.c)); } } #endif