You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.3 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: frdescam <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/17 17:09:48 by frdescam #+# #+# */
/* Updated: 2021/08/02 14:48:20 by frdescam ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STACK_HPP
# define STACK_HPP
# include <vector>
namespace ft
{
template <class T, class Container = std::vector<T> >
class stack
{
public:
typedef T value_type;
typedef Container container_type;
typedef std::size_t size_type;
protected:
container_type c;
public:
explicit stack(const container_type &ctnr = container_type()) : c(ctnr)
{
/* NOP */
}
bool empty(void) const
{
return c.empty();
}
size_type size(void) const
{
return c.size();
}
value_type top(void)
{
return c.back();
}
const value_type top(void) const
{
return c.back();
}
void push(const value_type &val)
{
c.push_back(val);
}
void pop(void)
{
c.pop_back();
}
friend bool operator==(const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs)
{
return lhs.c == rhs.c;
}
friend bool operator!=(const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs)
{
return lhs.c != rhs.c;
}
friend bool operator<(const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs)
{
return lhs.c < rhs.c;
}
friend bool operator<=(const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs)
{
return lhs.c <= rhs.c;
}
friend bool operator>(const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs)
{
return lhs.c > rhs.c;
}
friend bool operator>=(const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs)
{
return lhs.c >= rhs.c;
}
};
}
#endif