Implements Stack class.
More...
#include <stack.h>
|
| using | value_type = T |
| | Alias for data type used in class.
|
| using | reference = T& |
| | Alias for reference to data type used in class.
|
| using | const_reference = const T& |
| | Alias for const reference to data type used in class.
|
|
|
| Stack ()=default |
| | Construct a new Stack object.
|
| | Stack (const std::initializer_list< T > &init_list) |
| | Construct a new Stack object using initializer list.
|
| | Stack (const Stack< T > &other) |
| | Construct a new Stack object using copy constructor.
|
| auto | operator= (const Stack< T > &other) -> Stack & |
| | Constructs Stack using copy assignment.
|
| | Stack (Stack< T > &&other) noexcept |
| | Construct a new Stack object using move constructor.
|
| auto | operator= (Stack< T > &&other) noexcept -> Stack & |
| | Assign Stack object using move assignment.
|
|
| ~Stack ()=default |
| | Destroy the Stack object.
|
| auto | top () -> reference |
| | Function returns pointer to Stack top element.
|
| auto | top () const -> const_reference |
| | Function returns pointer to Stack top element.
|
| auto | empty () const -> bool |
| | Function checks if container has no elements.
|
| auto | size () const -> size_t |
| | Function returns Stack size.
|
| void | push (T value) |
| | Function add new element at the top of Stack.
|
| void | pop () |
| | Function removes the top element of Stack.
|
| void | swap (Stack< T > &other) noexcept |
| | Function swaps content of two Stack objects.
|
|
| auto | operator== (const Stack< T > &stack1, const Stack< T > &stack2) -> bool |
| | Forward friend declaration to access internal container comparison operator.
|
| auto | operator< (const Stack< T > &stack1, const Stack< T > &stack2) -> bool |
| | Forward friend declaration to access internal container comparison operator.
|
template<typename T>
class dsa::Stack< T >
Implements Stack class.
- Template Parameters
-
| T | type of data stored in Stack |
- Todo
add operator<=>
add emplace
add non-member specialized swap function
Definition at line 43 of file stack.h.
◆ const_reference
Alias for const reference to data type used in class.
- Template Parameters
-
| T& | const reference to data type |
Definition at line 66 of file stack.h.
◆ reference
Alias for reference to data type used in class.
- Template Parameters
-
Definition at line 59 of file stack.h.
◆ value_type
Alias for data type used in class.
- Template Parameters
-
Definition at line 52 of file stack.h.
◆ Stack() [1/3]
template<typename T>
| dsa::Stack< T >::Stack |
( |
const std::initializer_list< T > & | init_list | ) |
|
Construct a new Stack object using initializer list.
- Parameters
-
| [in] | init_list | initializer list of values of type T |
Definition at line 182 of file stack.h.
183 {
185 {
186 container.push_back(
item);
187 }
188 }
◆ Stack() [2/3]
Construct a new Stack object using copy constructor.
- Parameters
-
| [in] | other | Stack object of type T |
Definition at line 191 of file stack.h.
192 {
194 {
196 {
197 container.push_back(
item);
198 }
199 }
200 }
auto size() const -> size_t
Function returns Stack size.
◆ Stack() [3/3]
Construct a new Stack object using move constructor.
Content of other object will be taken by constructed object
- Parameters
-
| [in,out] | other | Stack object of type T |
Definition at line 222 of file stack.h.
◆ empty()
Function checks if container has no elements.
- Return values
-
| true | if container is empty |
| false | if container is not empty |
Definition at line 251 of file stack.h.
252 {
253 return container.size() == 0;
254 }
◆ operator=() [1/2]
Constructs Stack using copy assignment.
- Parameters
-
| [in] | other | Stack object of type T |
- Returns
- Stack& reference to Stack object
Definition at line 203 of file stack.h.
204 {
206 {
207 while (!container.empty())
208 {
209 container.pop_front();
210 }
211
213 {
214 container.push_back(
item);
215 }
216 }
217
218 return *this;
219 }
◆ operator=() [2/2]
Assign Stack object using move assignment.
Content of other object will be taken by constructed object
- Parameters
-
| [in,out] | other | Stack object of type T |
- Returns
- Stack& reference to Stack object
Definition at line 228 of file stack.h.
229 {
231 {
233 }
234
235 return *this;
236 }
◆ pop()
Function removes the top element of Stack.
Definition at line 269 of file stack.h.
270 {
271 container.pop_back();
272 }
◆ push()
Function add new element at the top of Stack.
- Parameters
-
| [in] | value | element of type T |
Definition at line 263 of file stack.h.
264 {
265 container.push_back(
value);
266 }
◆ size()
Function returns Stack size.
- Returns
- size_t number of elements in container
Definition at line 257 of file stack.h.
258 {
259 return container.size();
260 }
◆ swap()
Function swaps content of two Stack objects.
- Parameters
-
| [in,out] | other | object to swap content with |
Definition at line 275 of file stack.h.
◆ top() [1/2]
Function returns pointer to Stack top element.
- Returns
- T& reference to Stack top element
Definition at line 239 of file stack.h.
240 {
241 return container.back();
242 }
◆ top() [2/2]
Function returns pointer to Stack top element.
- Returns
- const T& const_reference to Stack top element
Definition at line 245 of file stack.h.
246 {
247 return container.back();
248 }
◆ operator<
template<typename T>
| auto operator< |
( |
const Stack< T > & | stack1, |
|
|
const Stack< T > & | stack2 ) -> bool |
|
friend |
Forward friend declaration to access internal container comparison operator.
- Template Parameters
-
| T | type of data stored in Stack |
- Parameters
-
| [in] | stack1 | input container |
| [in] | stack2 | input container |
- Return values
-
| true | if the content of stack1 are lexicographically less than the content of stack2 |
| false | otherwise |
Definition at line 346 of file stack.h.
◆ operator==
template<typename T>
| auto operator== |
( |
const Stack< T > & | stack1, |
|
|
const Stack< T > & | stack2 ) -> bool |
|
friend |
Forward friend declaration to access internal container comparison operator.
- Template Parameters
-
| T | type of data stored in Stack |
- Parameters
-
| [in] | stack1 | input container |
| [in] | stack2 | input container |
- Return values
-
| true | if containers are equal |
| false | if containers are not equal |
Definition at line 315 of file stack.h.
The documentation for this class was generated from the following file: