separate stack hpp and stack tpp
This commit is contained in:
@@ -21,25 +21,27 @@ public:
|
|||||||
* copliens :
|
* copliens :
|
||||||
************/
|
************/
|
||||||
// constructors ------------------------------
|
// constructors ------------------------------
|
||||||
explicit stack(const container_type& cont = Container()) : c(cont) {}
|
explicit stack(const container_type& cont = Container());
|
||||||
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* overload functions :
|
* overload functions :
|
||||||
**********************/
|
**********************/
|
||||||
// empty -------------------------------------
|
// empty -------------------------------------
|
||||||
bool empty() const { return c.empty(); }
|
bool empty() const ;
|
||||||
// size --------------------------------------
|
// size --------------------------------------
|
||||||
size_type size() const { return c.size(); }
|
size_type size() const ;
|
||||||
// top ---------------------------------------
|
// top ---------------------------------------
|
||||||
value_type& top() { return c.back(); }
|
value_type& top();
|
||||||
const value_type& top() const { return c.back(); }
|
const value_type& top() const ;
|
||||||
// push --------------------------------------
|
// push --------------------------------------
|
||||||
void push(const value_type& value) { c.push_back(value); }
|
void push(const value_type& value);
|
||||||
// pop ---------------------------------------
|
// pop ---------------------------------------
|
||||||
void pop() { c.pop_back(); }
|
void pop();
|
||||||
|
|
||||||
// Relational Operators (friend)
|
/*********************************
|
||||||
|
* Relational Operators (friend) :
|
||||||
|
*********************************/
|
||||||
template < typename T2, typename C2 >
|
template < typename T2, typename C2 >
|
||||||
friend bool operator==(const stack<T2,C2>& lhs, const stack<T2,C2>& rhs);
|
friend bool operator==(const stack<T2,C2>& lhs, const stack<T2,C2>& rhs);
|
||||||
template < typename T2, typename C2 >
|
template < typename T2, typename C2 >
|
||||||
@@ -58,36 +60,9 @@ protected:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/************************
|
|
||||||
* non-member functions :
|
|
||||||
************************/
|
|
||||||
// operator == -------------------------------
|
|
||||||
template < typename T, typename Container >
|
|
||||||
bool operator==(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
|
|
||||||
{ return lhs.c == rhs.c; }
|
|
||||||
// operator != -------------------------------
|
|
||||||
template < typename T, typename Container >
|
|
||||||
bool operator!=(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
|
|
||||||
{ return lhs.c != rhs.c; }
|
|
||||||
// operator < --------------------------------
|
|
||||||
template < typename T, typename Container >
|
|
||||||
bool operator<(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
|
|
||||||
{ return lhs.c < rhs.c; }
|
|
||||||
// operator > --------------------------------
|
|
||||||
template < typename T, typename Container >
|
|
||||||
bool operator>(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
|
|
||||||
{ return lhs.c > rhs.c; }
|
|
||||||
// operator <= -------------------------------
|
|
||||||
template < typename T, typename Container >
|
|
||||||
bool operator<=(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
|
|
||||||
{ return lhs.c <= rhs.c; }
|
|
||||||
// operator >= -------------------------------
|
|
||||||
template < typename T, typename Container >
|
|
||||||
bool operator>=(const stack<T, Container>& lhs, const stack<T, Container>& rhs)
|
|
||||||
{ return lhs.c >= rhs.c; }
|
|
||||||
|
|
||||||
} // namespace ft
|
} // namespace ft
|
||||||
|
|
||||||
|
# include "stack.tpp"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
72
templates/stack.tpp
Normal file
72
templates/stack.tpp
Normal 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
|
||||||
|
|
||||||
@@ -461,36 +461,37 @@ VT_TPL void VT::
|
|||||||
* non-member functions :
|
* non-member functions :
|
||||||
************************/
|
************************/
|
||||||
// operator == -------------------------------
|
// operator == -------------------------------
|
||||||
VT_TPL
|
VT_TPL bool
|
||||||
bool operator== (const VT & lhs, const VT & rhs) {
|
operator== (const VT & lhs, const VT & rhs) {
|
||||||
|
|
||||||
if (lhs.size() != rhs.size())
|
if (lhs.size() != rhs.size())
|
||||||
return false;
|
return false;
|
||||||
return ft::equal(lhs.begin(), lhs.end(), rhs.begin());
|
return ft::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||||
}
|
}
|
||||||
// operator < --------------------------------
|
// operator < --------------------------------
|
||||||
VT_TPL
|
VT_TPL bool
|
||||||
bool operator< (const VT & lhs, const VT & rhs) {
|
operator< (const VT & lhs, const VT & rhs) {
|
||||||
|
|
||||||
return ft::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
return ft::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
||||||
}
|
}
|
||||||
// operator != -------------------------------
|
// operator != -------------------------------
|
||||||
VT_TPL
|
VT_TPL bool
|
||||||
bool operator!= (const VT & lhs, const VT & rhs) { return !(lhs == rhs); }
|
operator!= (const VT & lhs, const VT & rhs) { return !(lhs == rhs); }
|
||||||
// operator <= -------------------------------
|
// operator <= -------------------------------
|
||||||
VT_TPL
|
VT_TPL bool
|
||||||
bool operator<= (const VT & lhs, const VT & rhs) { return !(lhs > rhs); }
|
operator<= (const VT & lhs, const VT & rhs) { return !(lhs > rhs); }
|
||||||
// operator > --------------------------------
|
// operator > --------------------------------
|
||||||
VT_TPL
|
VT_TPL bool
|
||||||
bool operator> (const VT & lhs, const VT & rhs) { return (rhs < lhs); }
|
operator> (const VT & lhs, const VT & rhs) { return (rhs < lhs); }
|
||||||
// operator >= -------------------------------
|
// operator >= -------------------------------
|
||||||
VT_TPL
|
VT_TPL bool
|
||||||
bool operator>= (const VT & lhs, const VT & rhs) { return !(lhs < rhs); }
|
operator>= (const VT & lhs, const VT & rhs) { return !(lhs < rhs); }
|
||||||
// swap (vector) -------------------------------
|
// swap (vector) -------------------------------
|
||||||
VT_TPL
|
VT_TPL void
|
||||||
void swap (VT & lhs, VT & rhs) { lhs.swap(rhs); }
|
swap (VT & lhs, VT & rhs) { lhs.swap(rhs); }
|
||||||
|
|
||||||
} // namespace ft
|
} // namespace ft
|
||||||
|
|
||||||
#undef VT
|
#undef VT
|
||||||
#undef VT_TPL
|
#undef VT_TPL
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user