separate stack hpp and stack tpp

This commit is contained in:
hugogogo
2022-07-01 12:52:57 +02:00
parent ef70cc5938
commit de5f718d0c
3 changed files with 99 additions and 51 deletions

72
templates/stack.tpp Normal file
View File

@@ -0,0 +1,72 @@
#define ST_TPL template <class T, class Container>
#define ST stack<T, Container>
namespace ft {
/************
* copliens :
************/
// constructors ------------------------------
ST_TPL ST::
stack(const container_type& cont)
: c(cont) {}
/**********************
* overload functions :
**********************/
// empty -------------------------------------
ST_TPL bool ST::
empty() const { return c.empty(); }
// size --------------------------------------
ST_TPL typename ST::size_type ST::
size() const { return c.size(); }
// top ---------------------------------------
ST_TPL typename ST::value_type& ST::
top() { return c.back(); }
ST_TPL const typename ST::value_type& ST::
top() const { return c.back(); }
// push --------------------------------------
ST_TPL void ST::
push(const value_type& value) { c.push_back(value); }
// pop ---------------------------------------
ST_TPL void ST::
pop() { c.pop_back(); }
/************************
* non-member functions :
************************/
// operator == -------------------------------
ST_TPL bool
operator==(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{ return lhs.c == rhs.c; }
// operator != -------------------------------
ST_TPL bool
operator!=(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{ return lhs.c != rhs.c; }
// operator < --------------------------------
ST_TPL bool
operator<(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{ return lhs.c < rhs.c; }
// operator > --------------------------------
ST_TPL bool
operator>(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{ return lhs.c > rhs.c; }
// operator <= -------------------------------
ST_TPL bool
operator<=(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{ return lhs.c <= rhs.c; }
// operator >= -------------------------------
ST_TPL bool
operator>=(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
{ return lhs.c >= rhs.c; }
} // namespace ft
#undef VT
#undef VT_TPL