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