-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.hpp
129 lines (88 loc) · 4.01 KB
/
stack.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mes-sadk <mes-sadk@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 10:35:45 by mes-sadk #+# #+# */
/* Updated: 2023/01/29 13:08:38 by mes-sadk ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STACK_HPP
# define STACK_HPP
# include"vector.hpp"
namespace ft {
/*************************************************************************************************************
* @category adaptor Containers
* @brief adapt the container as an stack funconality, LIFO D-S
* @param T value type
* @param Container Container to adapt it
*************************************************************************************************************/
template <class T, class Container = ft::vector<T> >
class stack {
public:
typedef Container container_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::size_type size_type;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
template<typename _T, typename con>
friend bool
operator== (const stack<_T, con>&, const stack<_T, con>&);
template<typename _T, typename con>
friend bool
operator< (const stack<_T, con>&, const stack<_T, con>&);
protected :
container_type c;
public:
/**
@category Constructor
@brief Default constracter that initialize the container
with default constructor or copy assi-cons i case of argement find;
@param cont container which the stack adapt it.
*/
explicit stack (const container_type& cont=container_type()): c(cont) { }
/**
@category copy Counstructor
@brief Needless to define غني عن تعريف
@param other vector to copie from it
*/
stack (const stack& other): c(other.c) { }
/**
@category operator
@brief Needless to define, equal to the same container operator
@param cont Container
*/
stack& operator= (const stack& cont) { c = cont.c; return *this; }
/** ******************* @category __Capacity__ ******************* */
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
/** ******************* @category __Modifiers__ ******************* */
void push (const value_type& value) { c.push_back(value); }
void pop() { c.pop_back(); }
/** ******************* @category __Element_access__ ******************* */
reference top() { return c.back(); }
/** ******************* @brief __destructor__ ******************* */
~stack() { };
};
template<typename _Tp, typename con>
bool operator== (const stack<_Tp, con>& _x, const stack<_Tp, con>& _y)
{ return _x.c == _y.c; }
template<typename _Tp, typename con>
bool operator< (const stack<_Tp, con>& _x, const stack<_Tp, con>& _y)
{ return _x.c < _y.c; }
template<typename _Tp, typename con>
bool operator!= (const stack<_Tp, con>& _x, const stack<_Tp, con>& _y)
{ return not (_x == _y); }
template<typename _Tp, typename con>
bool operator> (const stack<_Tp, con>& _x, const stack<_Tp, con>& _y)
{ return _y < _x; }
template<typename _Tp, typename con>
bool operator<= (const stack<_Tp, con>& _x, const stack<_Tp, con>& _y)
{ return not ( _y < _x); }
template<typename _Tp, typename con>
bool operator>= (const stack<_Tp, con>& _x, const stack<_Tp, con>& _y)
{ return not (_x < _y); }
};
# endif