-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ef1196
commit 5e91c93
Showing
3 changed files
with
145 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <deque> | ||
#include <iostream> | ||
#include <queue> | ||
|
||
template <typename T, int MaxLen, typename Container = std::deque<T>> | ||
class FixedQueue : public std::queue<T, Container> { | ||
public: | ||
FixedQueue() { | ||
for (auto i = 0; i < MaxLen; i++) { | ||
T default_value{}; | ||
std::queue<T, Container>::push(default_value); | ||
} | ||
} | ||
|
||
void push(const T& value) { | ||
if (this->size() == MaxLen) { | ||
this->c.pop_front(); | ||
} | ||
std::queue<T, Container>::push(value); | ||
} | ||
|
||
void pop(const T& value) { std::logic_error("Function not implemented"); } | ||
|
||
typename Container::iterator begin() { return this->c.begin(); } | ||
|
||
typename Container::reverse_iterator rbegin() { return this->c.rbegin(); } | ||
|
||
typename Container::iterator end() { return this->c.end(); } | ||
|
||
typename Container::reverse_iterator rend() { return this->c.rend(); } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters