15 #ifndef _DATAT_BITS_INCLUDE_TAG
16 #error Must only be included from sag_connectivity_cpp.hpp, use that instead
34 class list_t:
protected sag_underlying_vector_t
40 static size_t MIN_CAPACITY() {
return 10; }
48 template<
typename DATA,
typename UNDERLYING>
49 struct _iterator:
public std::iterator<std::random_access_iterator_tag, DATA>
52 _iterator() : ptr(
nullptr), direction(1) {}
53 explicit _iterator(UNDERLYING ptr,
bool forward=
true)
54 : ptr(ptr), direction(forward?1:-1)
56 iterator &operator+=(
size_t n) { ptr += direction*n;
return *
this; }
57 iterator &operator-=(
size_t n) { ptr -= direction*n;
return *
this; }
58 iterator operator+(
size_t n)
const {
return iterator(ptr+(direction*n), direction>0); }
59 iterator operator-(
size_t n)
const {
return iterator(ptr+(direction*-n), direction > 0); }
60 ptrdiff_t operator-(
const iterator &other)
const {
return direction*(ptr-other.ptr); }
61 DATA &operator[](
size_t n)
const {
return static_cast<DATA&
>(ptr[n*direction]); }
62 bool operator<(
const iterator &other)
const {
return direction>0 ? ptr < other.ptr : ptr > other.ptr; }
63 bool operator>(
const iterator &other)
const {
return direction>0 ? ptr > other.ptr : ptr < other.ptr; }
64 bool operator>=(
const iterator &other)
const {
return direction>0 ? ptr >= other.ptr : ptr <= other.ptr; }
65 bool operator<=(
const iterator &other)
const {
return direction>0 ? ptr <= other.ptr : ptr >= other.ptr; }
66 bool operator==(
const iterator &other)
const {
return ptr == other.ptr; }
67 bool operator!=(
const iterator &other)
const {
return !operator==(other); }
68 iterator &operator++() {
return operator+=(1); }
69 iterator operator++(
int)
75 iterator &operator--() {
return operator-=(1); }
76 iterator operator--(
int)
82 DATA &operator*()
const {
return static_cast<DATA&
>(*ptr); }
83 DATA *operator->()
const {
return static_cast<DATA*
>(ptr); }
112 swap(std::move(tmp));
114 swap(std::move(other));
121 swap(std::move(other));
128 for(
auto it = l.begin(); it != l.end(); ++it) {
136 std::swap(table, other.table);
142 for (const_iterator it =
begin(); it !=
end(); ++it) {
167 iterator
end() {
return iterator(table?table->data+table->count:0); }
177 iterator
rbegin() {
return iterator(table?table->data+table->count-1:0,
false); }
186 size_t size()
const {
return table?table->count:0; }
212 if (!table) resize(n);
213 if (n > table->capacity) resize(n);
235 void resize(
size_t newsize);
bool empty() const
Returns true if there are no items in this list.
Definition: list_t.hpp:188
list_t(list_t &&other)
Move construction.
Definition: list_t.hpp:118
list_t()
Construct an empty list.
Definition: list_t.hpp:93
list_t(std::initializer_list< data_t > l)
Initialiser list construction.
Definition: list_t.hpp:125
void push_back(data_t &&d)
Add an item to the end of the list.
A list class which implements many of the functions on std::vector.
Definition: list_t.hpp:34
A container for an payload and associated metadata.
Definition: message.hpp:27
list_t copy() const
Return a deep copy of this list.
Definition: list_t.hpp:139
A map class which implements many of the functions on std::map.
Definition: map_t.hpp:36
void pop_back()
Remove the last item in the list.
~list_t()
Free the underlying list.
Definition: list_t.hpp:101
list_t & operator=(list_t &&other)
Move assignment operator.
Definition: list_t.hpp:108
_iterator< const data_t, const sag_underlying_data_t * > const_iterator
The type of iterators over a const list.
Definition: list_t.hpp:90
const_iterator end() const
Forward const_iterator end.
Definition: list_t.hpp:171
const data_t & front() const
Returns a reference to the data_t at position 0 Throws std::runtime_error if the list is empty...
Definition: list_t.hpp:198
bool operator!=(const list_t &other) const
Returns false if this list is deep equals to other list.
Definition: list_t.hpp:159
bool operator==(const list_t &other) const
Returns true if this list is deep equals to other list.
void clear()
Clear the list and free the underlying data structure (capacity is now 0)
iterator begin()
Forward iterator begin.
Definition: list_t.hpp:165
const_iterator cbegin() const
Forward const_iterator begin.
Definition: list_t.hpp:173
const data_t & back() const
Returns a reference to the data_t at position size()-1 Throws std::runtime_error if the list is empty...
Definition: list_t.hpp:201
iterator rend()
Reverse iterator end.
Definition: list_t.hpp:179
size_t size() const
Return the number of items in this list.
Definition: list_t.hpp:186
data_t & front()
Returns a reference to the data_t at position 0 Throws std::runtime_error if the list is empty...
Definition: list_t.hpp:204
data_t & back()
Returns a reference to the data_t at position size()-1 Throws std::runtime_error if the list is empty...
Definition: list_t.hpp:207
iterator end()
Forward iterator end.
Definition: list_t.hpp:167
void swap(list_t &&other)
Swap the contents of this list with other.
Definition: list_t.hpp:134
iterator rbegin()
Reverse iterator begin.
Definition: list_t.hpp:177
Forward/reverse and const/non-const iterators are implemented using this class.
Definition: list_t.hpp:49
void reserve(size_t n)
Ensure the capacity is (at least) n.
Definition: list_t.hpp:210
const_iterator cend() const
Forward const_iterator end.
Definition: list_t.hpp:175
const_iterator begin() const
Forward const_iterator begin.
Definition: list_t.hpp:169
A variant type which can be one of the following:
Definition: data_t.hpp:42
const data_t & operator[](size_t n) const
Returns a reference to the data_t at position n.
_iterator< data_t, sag_underlying_data_t * > iterator
The type of iterators over a mutable list.
Definition: list_t.hpp:88
const_iterator rend() const
Reverse const_iterator end.
Definition: list_t.hpp:183
const_iterator rbegin() const
Reverse const_iterator begin.
Definition: list_t.hpp:181