forked from quickshell/quickshell
core/stacklist: add tests
This commit is contained in:
parent
6024c37492
commit
c2ed5bf559
4 changed files with 123 additions and 1 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
#include <qlist.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
template <class T, size_t N>
|
||||
|
@ -40,13 +41,24 @@ public:
|
|||
[[nodiscard]] bool operator==(const StackList<T, N>& other) const {
|
||||
if (other.size != this->size) return false;
|
||||
|
||||
for (size_t i = 0; i < this->size; ++i) {
|
||||
for (size_t i = 0; i != this->size; ++i) {
|
||||
if (this->operator[](i) != other[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] QList<T> toList() const {
|
||||
QList<T> list;
|
||||
list.reserve(this->size);
|
||||
|
||||
for (const auto& entry: *this) {
|
||||
list.push_back(entry);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
template <typename Self, typename ListPtr, typename IT>
|
||||
struct BaseIterator {
|
||||
using iterator_category = std::bidirectional_iterator_tag;
|
||||
|
@ -65,6 +77,7 @@ public:
|
|||
++this->i;
|
||||
return *static_cast<Self*>(this);
|
||||
}
|
||||
|
||||
Self& operator--() {
|
||||
--this->i;
|
||||
return *static_cast<Self*>(this);
|
||||
|
@ -75,6 +88,7 @@ public:
|
|||
this->operator++();
|
||||
return v;
|
||||
}
|
||||
|
||||
Self operator--(int) {
|
||||
auto v = *this;
|
||||
this->operator--();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue