1 #ifndef TERMOX_COMMON_UNIQUE_QUEUE_HPP
2 #define TERMOX_COMMON_UNIQUE_QUEUE_HPP
9 #include <termox/common/transform_iterator.hpp>
21 struct Ordered_element {
29 [[nodiscard]]
auto operator()(Ordered_element
const& e)
const
35 [[nodiscard]]
auto operator()(Ordered_element& e)
const -> T&
41 using Internal_container_t = std::vector<Ordered_element>;
55 assert(!compressed_but_not_cleared_);
56 data_.push_back({count_, element});
63 assert(!compressed_but_not_cleared_);
64 data_.push_back({count_, std::move(element)});
68 [[nodiscard]]
auto size() const -> std::
size_t {
return data_.size(); }
77 std::begin(data_), std::end(data_),
78 [](Ordered_element
const& a, Ordered_element
const& b) {
79 return a.element < b.element;
82 std::unique(std::rbegin(data_), std::rend(data_),
83 [](Ordered_element
const& a, Ordered_element
const& b) {
84 return a.element == b.element;
86 data_.erase(std::begin(data_), rend.base());
87 std::sort(std::begin(data_), std::end(data_),
88 [](Ordered_element
const& a, Ordered_element
const& b) {
89 return a.position < b.position;
92 compressed_but_not_cleared_ =
true;
102 compressed_but_not_cleared_ =
false;
106 [[nodiscard]]
auto begin() -> iterator
108 return iterator{std::begin(data_), get_element_};
111 [[nodiscard]]
auto begin() const -> const_iterator
113 return const_iterator{std::cbegin(data_), get_element_};
116 [[nodiscard]]
auto end() -> iterator
118 return iterator{std::end(data_), get_element_};
121 [[nodiscard]]
auto end() const -> const_iterator
123 return const_iterator{std::cend(data_), get_element_};
127 Internal_container_t data_;
128 Get_element get_element_;
131 bool compressed_but_not_cleared_ =
false;
A Queue like container holding only unique values.
Definition: unique_queue.hpp:19
void append(T const &element)
Add element to the end of the queue.
Definition: unique_queue.hpp:53
void compress()
Remove duplicate elements, this should be called before using iterators.
Definition: unique_queue.hpp:74
void append(T &&element)
Add element to the end of the queue.
Definition: unique_queue.hpp:61
void clear()
Remove all elements from the queue.
Definition: unique_queue.hpp:97