45 : impl(std::make_move_iterator(other.begin()), std::make_move_iterator(other.end())) {}
57 impl.push_front(value);
65 impl.push_front(std::move(value));
73 impl.push_back(value);
81 impl.push_back(std::move(value));
91 const auto result = std::move(impl.front());
99 std::vector<T>
lpop(
size_t count) {
100 count = std::min(count, impl.size());
101 std::vector<T> result(std::make_move_iterator(impl.begin()),
102 std::make_move_iterator(impl.begin() + count));
103 impl.erase(impl.begin(), impl.begin() + count);
113 const auto result = std::move(impl.back());
121 std::vector<T>
rpop(
size_t count) {
122 count = std::min(count, impl.size());
123 std::vector<T> result(std::make_move_iterator(impl.end() - count),
124 std::make_move_iterator(impl.end()));
125 impl.erase(impl.end() - count, impl.end());
143 std::vector<T>
lrange(
int start,
int stop)
const {
144 start = start < 0 ?
size() + start : start;
145 stop = stop < 0 ?
size() + stop : stop;
148 if (start > stop || start >= (
int)
size() || stop < 0) {
152 start = std::max(0, start);
153 stop = std::min(stop, (
int)
size() - 1);
155 std::vector<T> result(impl.begin() + start, impl.begin() + stop + 1);
165 size_t size()
const {
return impl.size(); }
169 bool empty()
const {
return impl.empty(); }
A Redis-compatible list supporting operations from both ends.
size_t lpush(const T &value)
Pushes a value to the front of the list (left push).
RedisList(const RedisList &other)=default
Copy constructor.
size_t llen() const
Returns the length of the list (Redis LLEN command).
std::vector< T > lpop(size_t count)
Removes and returns up to count elements from the front.
std::optional< T > rpop()
Removes and returns the last element (right pop).
size_t rpush(T &&value)
Pushes a value to the back of the list (right push).
bool empty() const
Checks if the list is empty.
~RedisList()=default
Default destructor.
RedisList & operator=(const RedisList &other)=default
Copy assignment operator.
std::optional< T > lpop()
Removes and returns the first element (left pop).
size_t lpush(T &&value)
Pushes a value to the front of the list (left push).
RedisList & operator=(RedisList &&other) noexcept=default
Move assignment operator.
std::vector< T > lrange(int start, int stop) const
Returns a range of elements without removing them.
std::vector< T > rpop(size_t count)
Removes and returns up to count elements from the back.
size_t size() const
Returns the number of elements in the list.
RedisList(RedisList &&other) noexcept=default
Move constructor.
RedisList(std::vector< T > &&other)
Constructs a RedisList from a vector by moving its elements.
size_t rpush(const T &value)
Pushes a value to the back of the list (right push).
RedisList()
Constructs an empty RedisList.