57 template <
typename Container,
typename T>
58 static void push(Container& container,
const T& value)
60 container.push_front(value);
62 template <
typename Container>
63 static void temp_to_output(Container& temp, Container& output)
81template <
typename T,
class Alloc>
99template <
typename T,
class Alloc>
118template <
typename T,
class Alloc>
119template <
typename InputIterator>
135template <
typename T,
class Alloc>
149template <
typename T,
class Alloc>
154 unlink_and_destroy_after(&head_);
166template <
typename T,
class Alloc>
184template <
typename T,
class Alloc>
185template <
typename ForwardIterator>
186void slist<T, Alloc>::assign(ForwardIterator first, ForwardIterator last)
201template <
typename T,
class Alloc>
202void slist<T, Alloc>::assign(size_type n,
const T& value)
214template <
typename T,
class Alloc>
215typename slist<T, Alloc>::allocator_type
218 return *
static_cast<const allocator_type*
>(
this);
227template <
typename T,
class Alloc>
228typename slist<T, Alloc>::iterator
231 return iterator(head_.next);
240template <
typename T,
class Alloc>
241typename slist<T, Alloc>::const_iterator
244 return const_iterator(head_.next);
253template <
typename T,
class Alloc>
254typename slist<T, Alloc>::iterator
266template <
typename T,
class Alloc>
267typename slist<T, Alloc>::const_iterator
270 return const_iterator(0);
283template <
typename T,
class Alloc>
284typename slist<T, Alloc>::iterator
287 return iterator(&head_);
300template <
typename T,
class Alloc>
301typename slist<T, Alloc>::const_iterator
304 return const_iterator(&head_);
316template <
typename T,
class Alloc>
317typename slist<T, Alloc>::iterator
332template <
typename T,
class Alloc>
333typename slist<T, Alloc>::const_iterator
351template <
typename T,
class Alloc>
352typename slist<T, Alloc>::iterator
355 iterator result = start;
356 while (result.node_->next != position.node_)
358 LASS_ASSERT(result.node_->next);
376template <
typename T,
class Alloc>
377typename slist<T, Alloc>::const_iterator
380 const_iterator result = start;
381 while (result.node_->next != position.node_)
383 LASS_ASSERT(result.node_->next);
397template <
typename T,
class Alloc>
400 return head_.next == 0;
409template <
typename T,
class Alloc>
410typename slist<T, Alloc>::size_type
414 for (node_base_t* i = head_.next; i != 0; i = i->next)
430template <
typename T,
class Alloc>
431typename slist<T, Alloc>::size_type
436 return size_type(-1);
449template <
typename T,
class Alloc>
452 node_base_t* i = &head_;
466 unlink_and_destroy_after(i);
480template <
typename T,
class Alloc>
481typename slist<T, Alloc>::reference
484 return static_cast<node_t*
>(head_.next)->value;
496template <
typename T,
class Alloc>
497typename slist<T, Alloc>::const_reference
500 return static_cast<node_t*
>(head_.next)->value;
514template <
typename T,
class Alloc>
517 node_base_t* node = make_node(value);
518 node->next = head_.next;
531template <
typename T,
class Alloc>
534 unlink_and_destroy_after(&head_);
551template <
typename T,
class Alloc>
552typename slist<T, Alloc>::iterator
555 const iterator before_position =
prior(position);
575template <
typename T,
class Alloc>
578 const iterator before_position =
prior(position);
599template <
typename T,
class Alloc>
600template <
typename InputIterator>
603 const iterator before_position =
prior(position);
618template <
typename T,
class Alloc>
619typename slist<T, Alloc>::iterator
622 node_base_t* new_node = make_node(value);
623 link_after(position.node_, new_node);
624 return iterator(new_node);
639template <
typename T,
class Alloc>
642 node_base_t* node = position.node_;
643 for (size_type i = 0; i < n; ++i)
645 node_t* new_node = make_node(value);
646 link_after(node, new_node);
664template <
typename T,
class Alloc>
665template <
typename InputIterator>
668 insert_after(position, first, last, meta::Wrap<
typename meta::IsIntegral<InputIterator>::Type>());
685template <
typename T,
class Alloc>
686typename slist<T, Alloc>::iterator
689 iterator before_position =
prior(position);
691 return ++before_position;
711template <
typename T,
class Alloc>
712typename slist<T, Alloc>::iterator
715 iterator before_position =
prior(position);
717 return ++before_position;
731template <
typename T,
class Alloc>
734 LASS_ASSERT(position.node_ && position.node_->next);
735 unlink_and_destroy_after(position.node_);
751template <
typename T,
class Alloc>
754 LASS_ASSERT(position.node_);
755 while (position.node_->next != last.node_)
769template <
typename T,
class Alloc>
773 std::swap(head_.next, other.head_.next);
782template <
typename T,
class Alloc>
805template <
typename T,
class Alloc>
808 const iterator before_position =
prior(position);
828template <
typename T,
class Alloc>
831 const iterator before_position =
prior(position);
832 const iterator before_x = other.
prior(x);
854template <
typename T,
class Alloc>
857 const iterator before_position =
prior(position);
858 const iterator before_first = other.
prior(first);
859 const iterator before_last = other.
prior(last, before_first);
860 splice_after(before_position, other, before_first, before_last);
875template <
typename T,
class Alloc>
878 node_base_t* other_before_last = &other.head_;
879 while (other_before_last->next)
881 other_before_last = other_before_last->next;
884 splice_after(position.node_, &other.head_, other_before_last);
899template <
typename T,
class Alloc>
902 splice_after(position.node_, before_x.node_, before_x.node_->next);
919template <
typename T,
class Alloc>
921 iterator before_last)
923 splice_after(position.node_, before_first.node_, before_last.node_);
934template <
typename T,
class Alloc>
937 node_base_t* node = &head_;
940 if (
static_cast<node_t*
>(node->next)->value == value)
942 unlink_and_destroy_after(node);
959template <
typename T,
class Alloc>
960template <
class UnaryPredicate>
963 node_base_t* node = &head_;
966 if (predicate(
static_cast<node_t*
>(node->next)->value))
968 unlink_and_destroy_after(node);
986template <
typename T,
class Alloc>
989 node_base_t* node = head_.next;
996 if (
static_cast<node_t*
>(node)->value ==
static_cast<node_t*
>(node->next)->value)
998 unlink_and_destroy_after(node);
1019template <
typename T,
class Alloc>
1020template <
class BinaryPredicate>
1023 node_base_t* node = head_.next;
1030 if (predicate(
static_cast<node_t*
>(node)->value,
static_cast<node_t*
>(node->next)->value))
1032 unlink_and_destroy_after(node);
1055template <
typename T,
class Alloc>
1058 merge(other, std::less<value_type>());
1077template <
typename T,
class Alloc>
1078template <
class BinaryPredicate>
1081 node_base_t* node = &head_;
1082 while (node->next && other.head_.next)
1084 if (compare(
static_cast<node_t*
>(other.head_.next)->value,
1085 static_cast<node_t*
>(node->next)->value))
1091 if (other.head_.next)
1093 node->next = other.head_.next;
1094 other.head_.next = 0;
1107template <
typename T,
class Alloc>
1110 sort(std::less<value_type>());
1129template <
typename T,
class Alloc>
1130template <
class BinaryPredicate>
1133 if (head_.next && head_.next->next)
1142 while (i < fill && !counter[i].
empty())
1144 counter[i].
merge(carry, compare);
1145 carry.
swap(counter[i]);
1148 carry.
swap(counter[i]);
1154 for (size_type i = 1; i < fill; ++i)
1156 counter[i].
merge(counter[i - 1], compare);
1158 swap(counter[fill - 1]);
1170template <
typename T,
class Alloc>
1173 node_base_t*
begin = 0;
1176 node_base_t* node = head_.next;
1177 head_.next = node->next;
1192template <
typename T,
class Alloc>
1193typename slist<T, Alloc>::node_t*
1194slist<T, Alloc>::make_node(
const T& value)
const
1196 allocator_type allocator = get_allocator();
1197 node_allocator_type node_allocator = node_allocator_type(allocator);
1199 node_t* node = node_allocator.allocate(1);
1202 std::allocator_traits<allocator_type>::construct(allocator, &node->value, value);
1206 node_allocator.deallocate(node, 1);
1217template <
typename T,
class Alloc>
1218void slist<T, Alloc>::unlink_and_destroy_after(node_base_t* before)
const
1220 allocator_type allocator = get_allocator();
1221 node_allocator_type node_allocator = node_allocator_type(allocator);
1223 LASS_ASSERT(before && before->next);
1225 node_base_t* node = before->next;
1226 before->next = node->next;
1227 std::allocator_traits<allocator_type>::destroy(allocator, &
static_cast<node_t*
>(node)->value);
1228 node_allocator.deallocate(
static_cast<node_t*
>(node), 1);
1235template <
typename T,
class Alloc>
1236void slist<T, Alloc>::link_after(node_base_t* position, node_base_t* node)
const
1238 LASS_ASSERT(position && node);
1239 node->next = position->next;
1240 position->next = node;
1247template <
typename T,
class Alloc>
1249 node_base_t* before_last)
const
1251 LASS_ASSERT(before_first != before_last);
1252 if (position != before_first && position != before_last)
1254 node_base_t*
const first = before_first->next;
1255 before_first->next = before_last->next;
1256 before_last->next = position->next;
1257 position->next = first;
1265template <
typename T,
class Alloc>
1266template <
typename IntegerType>
1269 insert_after(position,
static_cast<size_t>(n),
static_cast<value_type>(value));
1276template <
typename T,
class Alloc>
1277template <
typename InputIterator>
1280 while (first != last)
1282 node_t* new_node = make_node(*first);
1283 link_after(position.node_, new_node);
1304template <
typename T,
class Alloc>
1307 typedef typename slist<T, Alloc>::const_iterator const_iterator;
1308 const const_iterator a_end = a.
end();
1309 const const_iterator b_end = b.
end();
1310 const_iterator i = a.
begin();
1311 const_iterator j = b.
begin();
1312 while (i != a_end && j != b_end)
1321 return i == a_end && j == b_end;
1336template <
typename T,
class Alloc>
1356template <
typename T,
class Alloc>
1359 typedef typename slist<T, Alloc>::const_iterator const_iterator;
1360 const const_iterator a_end = a.
end();
1361 const const_iterator b_end = b.
end();
1362 const_iterator i = a.
begin();
1363 const_iterator j = b.
begin();
1364 while (i != a_end && j != b_end)
1388template <
typename T,
class Alloc>
1406template <
typename T,
class Alloc>
1424template <
typename T,
class Alloc>
1440template <
typename T,
class Alloc,
typename Char,
typename Traits>
1441std::basic_ostream<Char, Traits>&
1442operator<<(std::basic_ostream<Char, Traits>& ostream,
1445 return impl::print_sequence(
1446 ostream, container.
begin(), container.
end(),
"[",
", ",
"]");
1459template <
typename T,
class Alloc,
typename Char,
typename Traits>
1460std::basic_istream<Char, Traits>&
1464 std::basic_istream<Char, Traits>& result =
1465 impl::read_container<impl::slist_traits, impl::value_traits, T, Char>(
1466 istream, container,
'[',
',', 0,
']');
void clear()
removes all elements from the list
void sort()
Sorts *this according to operator<.
void splice_after(iterator position, slist< T, Alloc > &other)
moves all elements from other to *this after position without copying, and clears other.
void merge(slist< T, Alloc > &other)
Merge two sorted containers to one big sorted.
bool operator==(const slist< T, Alloc > &a, const slist< T, Alloc > &b)
returns wether a and b are lexicographical idential.
slist(const Alloc &allocator=Alloc())
Creates an empty list, using the provided allocator.
iterator end()
returns an iterator for the position after the last element of the list.
iterator before_begin()
returns an iterator for the position before the first element of the list.
~slist()
destroys all elements and frees memory.
reference front()
returns reference to first element in list.
iterator begin()
returns an iterator to the first element of the list.
void push_front(const T &value)
insert a copy of value at the front of the list so that the current list comes behind it.
void unique()
removes all but the first element in every consecutive group of equal elements.
bool operator>=(const slist< T, Alloc > &a, const slist< T, Alloc > &b)
size_type size() const
returns the N, the number of elements in the list.
iterator erase(iterator position)
removes element at iterator position from the list and return iterator to the next element.
size_type max_size() const
returns a very rough estimation on what's the maximum number of elements you can ever have in an slis...
bool operator<(const slist< T, Alloc > &a, const slist< T, Alloc > &b)
returns wether a is lexicographical less than b.
bool empty() const
returns wether the list is empty.
iterator insert(iterator position, const T &value)
inserts a new element before iterator position and returns iterator to it.
void remove(const T &value)
removes all elements with iterarors i for which *i == value
void splice(iterator position, slist< T, Alloc > &other)
moves all elements from other to *this before position without copying, and clears other.
bool operator!=(const slist< T, Alloc > &a, const slist< T, Alloc > &b)
returns wether a and b are not lexicographical idential.
slist< T, Alloc > & operator=(slist< T, Alloc > other)
replace *this by a copy of other.
iterator prior(iterator position) const
return the iterator that sits position and start searching for it from start.
void pop_front()
erases the first element in the list.
iterator insert_after(iterator position, const T &value)
inserts a new element after iterator position and returns iterator to it.
void resize(size_type n, const T &value=T())
at the end of the list, inserts copies of value or erases elements so that list size is n.
void erase_after(iterator position)
removes element after iterator position from the list.
void swap(slist< T, Alloc > &other)
void remove_if(UnaryPredicate predicate)
removes all elements with iterarors i for which predicate(*i) yields true.
std::basic_istream< Char, Traits > & operator>>(std::basic_istream< Char, Traits > &istream, slist< T, Alloc > &container)
reads list from stream.
allocator_type get_allocator() const
returns the memory model of the list.
void reverse()
reverses the order of the elements.
bool operator>(const slist< T, Alloc > &a, const slist< T, Alloc > &b)
returns wether b is lexicographical less than a.
bool operator<=(const slist< T, Alloc > &a, const slist< T, Alloc > &b)
returns wether a is lexicographical less or equal to b.
lass extensions to the standard library
Library for Assembled Shared Sources.