17 template <
class Hash,
class Compare>
31 template <
bool IsConst>
40 using pointer = std::conditional_t<
49 Iterator(
const Iterator<false>& other):
69 friend bool operator==(Iterator<IsConst> left, Iterator<IsConst> right)
71 return left.pos_ == right.pos_;
74 friend bool operator!=(Iterator<IsConst> left, Iterator<IsConst> right)
75 {
return not (left == right); }
77 Iterator& operator++()
85 Iterator operator++(
int)
97 return not
static_cast<bool>(*pos_);
103 return not
static_cast<bool>(pos_);
107 using pos_type = std::conditional_t<IsConst, value_type* const*, value_type**>;
109 Iterator(pos_type p):
115 Iterator<false> to_non_const()
const 117 return Iterator<false>(&
const_cast<value_type*&
>(*pos_));
120 pos_type pos_ =
nullptr;
122 friend struct AnyList<Hash, Compare>;
123 template <
class,
class,
class>
124 friend struct ::te::AnySet;
128 using iterator = Iterator<false>;
129 using const_iterator = Iterator<true>;
131 void _assert_invariants()
const 133 assert(not static_cast<bool>(*tail_));
136 assert(size() == 0u);
138 assert(not static_cast<bool>(head_));
142 assert(size() != 0u);
144 assert(static_cast<bool>(head_));
146 assert(static_cast<size_type>(
std::distance(begin(), end())) == size());
154 head_(other.head_), tail_(other.tail_), count_(other.count_)
156 other.head_ =
nullptr;
157 other.tail_ = &(other.head_);
174 for(
const auto& any_v: other)
176 splice(it, any_v.clone());
190 count_ = other.count_;
191 tail_ = (other.tail_ == &(other.head_)) ? &head_ : other.tail_;
192 other.head_ =
nullptr;
193 other.tail_ = &(other.head_);
199 {
return iterator(&head_); }
200 const_iterator begin()
const 201 {
return const_iterator(&head_); }
202 const_iterator cbegin()
const 203 {
return const_iterator(&head_); }
207 assert(static_cast<bool>(tail_));
208 assert(not static_cast<bool>(*tail_));
209 return iterator(tail_);
211 const_iterator end()
const 213 assert(static_cast<bool>(tail_));
214 assert(not static_cast<bool>(*tail_));
215 return const_iterator(tail_);
218 const_iterator cend()
const 220 assert(static_cast<bool>(tail_));
221 assert(not static_cast<bool>(*tail_));
222 return const_iterator(tail_);
238 assert(other.size() == 0);
246 erase(begin(), end());
247 assert(not static_cast<bool>(head_));
255 assert(not static_cast<bool>(*tail_));
256 assert(static_cast<bool>(node));
257 assert(not static_cast<bool>(node->next));
258 *tail_ = node.release();
259 iterator old_tail(tail_);
262 assert(not static_cast<bool>(*tail_));
268 assert(not static_cast<bool>(*tail_));
272 if(not static_cast<bool>(pos->next))
275 node->next =
nullptr;
277 assert(not static_cast<bool>(*tail_));
283 assert(not static_cast<bool>(*tail_));
285 if(not static_cast<bool>(pos))
288 pos = node.release();
290 assert(not static_cast<bool>(*tail_));
291 return p.to_non_const();
294 iterator erase(const_iterator p)
298 return p.to_non_const();
306 auto* last_pos = *last.pos_;
307 while(*first.pos_ != last_pos)
308 first = erase(first);
315 bool empty()
const noexcept
317 assert(static_cast<bool>(size()) == static_cast<bool>(head_));
318 assert((tail_ == &head_) ? size() == 0u : size() > 0u);
319 return not
static_cast<bool>(size());
323 { left.swap(right); }
335 template <
class Hash,
class Compare>
338 auto lpos = left.begin();
339 auto rpos = right.begin();
340 while((not lpos.is_end()) and (not rpos.is_end()))
342 if(not (*lpos++ == *rpos++))
345 assert(lpos.is_end() or rpos.is_end());
346 return lpos.is_end() and rpos.is_end();
349 template <
class Hash,
class Compare>
351 {
return not (left == right); }
Definition: AnyList.h:168
Definition: SetOperations.h:23