ORIGINAL
Loading...
Searching...
No Matches
stack.h
1#ifndef STACK_H
2#define STACK_H
3
4#include "chain.h"
5#include "containerAdapter.h"
6#include <string>
7
8namespace original {
9 template<typename TYPE, template <typename> typename SERIAL = chain>
10 class stack final : public containerAdapter<TYPE, SERIAL> {
11 public:
12 explicit stack(const SERIAL<TYPE>& serial = SERIAL<TYPE>{});
13 stack(const std::initializer_list<TYPE>& lst);
14 stack(const stack& other);
15 stack& operator=(const stack& other);
16 stack(stack&& other) noexcept;
17 stack& operator=(stack&& other) noexcept;
18 bool operator==(const stack& other) const;
19 void push(const TYPE& e);
20 TYPE pop();
21 TYPE top() const;
22 [[nodiscard]] std::string className() const override;
23 };
24}
25
26 template<typename TYPE, template <typename> typename SERIAL>
27 original::stack<TYPE, SERIAL>::stack(const SERIAL<TYPE>& serial)
28 : containerAdapter<TYPE, SERIAL>(serial) {}
29
30 template<typename TYPE, template <typename> typename SERIAL>
31 original::stack<TYPE, SERIAL>::stack(const std::initializer_list<TYPE> &lst)
32 : stack(SERIAL<TYPE>(lst)) {}
33
34 template<typename TYPE, template <typename> typename SERIAL>
35 original::stack<TYPE, SERIAL>::stack(const stack& other)
36 : containerAdapter<TYPE, SERIAL>(other.serial_) {}
37
38 template<typename TYPE, template <typename> typename SERIAL>
39 auto original::stack<TYPE, SERIAL>::operator=(const stack& other) -> stack& {
40 if (this == &other) return *this;
41 this->serial_ = other.serial_;
42 return *this;
43 }
44
45 template <typename TYPE, template <typename> class SERIAL>
46 original::stack<TYPE, SERIAL>::stack(stack&& other) noexcept : stack()
47 {
48 this->operator=(std::move(other));
49 }
50
51 template <typename TYPE, template <typename> class SERIAL>
52 auto original::stack<TYPE, SERIAL>::operator=(stack&& other) noexcept -> stack&
53 {
54 if (this == &other)
55 return *this;
56
57 this->serial_ = std::move(other.serial_);
58 other.serial_ = SERIAL<TYPE>{};
59 return *this;
60 }
61
62 template<typename TYPE, template <typename> typename SERIAL>
63 auto original::stack<TYPE, SERIAL>::operator==(const stack& other) const -> bool {
64 return this->serial_ == other.serial_;
65 }
66
67 template<typename TYPE, template <typename> typename SERIAL>
68 auto original::stack<TYPE, SERIAL>::push(const TYPE& e) -> void {
69 this->serial_.pushEnd(e);
70 }
71
72 template<typename TYPE, template <typename> typename SERIAL>
73 auto original::stack<TYPE, SERIAL>::pop() -> TYPE {
74 return this->serial_.popEnd();
75 }
76
77 template<typename TYPE, template <typename> typename SERIAL>
78 auto original::stack<TYPE, SERIAL>::top() const -> TYPE {
79 return this->serial_.getEnd();
80 }
81
82 template<typename TYPE, template <typename> typename SERIAL>
83 std::string original::stack<TYPE, SERIAL>::className() const {
84 return "stack";
85 }
86
87#endif // STACK_H
Definition chain.h:13
Definition containerAdapter.h:10
Definition serial.h:8
Definition stack.h:10