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