48#ifndef LASS_GUARDIAN_OF_INCLUSION_STDE_SLIST_H
49#define LASS_GUARDIAN_OF_INCLUSION_STDE_SLIST_H
61template <
typename T,
class Alloc = std::allocator<T> >
71 struct node_t:
public node_base_t
79 typedef value_type& reference;
80 typedef const value_type& const_reference;
81 typedef typename std::allocator_traits<Alloc>::template rebind_alloc<value_type> allocator_type;
82 typedef typename std::allocator_traits<allocator_type>::pointer pointer;
83 typedef typename std::allocator_traits<allocator_type>::const_pointer const_pointer;
84 typedef typename std::allocator_traits<allocator_type>::size_type size_type;
85 typedef typename std::allocator_traits<allocator_type>::difference_type difference_type;
87 friend class const_iterator;
89 friend class iterator;
94 typedef typename slist<T, Alloc>::value_type value_type;
95 typedef typename slist<T, Alloc>::pointer pointer;
96 typedef typename slist<T, Alloc>::reference reference;
97 typedef typename slist<T, Alloc>::size_type size_type;
98 typedef typename slist<T, Alloc>::difference_type difference_type;
99 typedef std::forward_iterator_tag iterator_category;
100 iterator(): node_(0) {}
101 reference operator*()
const
104 return static_cast<node_t* const
>(node_)->value;
106 pointer operator->()
const
109 return &
static_cast<node_t* const
>(node_)->value;
111 iterator& operator++() { node_ = node_->next;
return *
this; }
112 iterator operator++(
int) { iterator result(*
this); ++(*this);
return result; }
113 bool operator==(
const iterator& other)
const {
return node_ == other.node_; }
114 bool operator!=(
const iterator& other)
const {
return !(*
this == other); }
116 friend class slist<T, Alloc>;
117 friend class const_iterator;
118 explicit iterator(node_base_t* node): node_(node) {}
125 typedef typename slist<T, Alloc>::value_type value_type;
126 typedef typename slist<T, Alloc>::pointer pointer;
127 typedef typename slist<T, Alloc>::reference reference;
128 typedef typename slist<T, Alloc>::size_type size_type;
129 typedef typename slist<T, Alloc>::difference_type difference_type;
130 typedef std::forward_iterator_tag iterator_category;
131 const_iterator(): node_(0) {}
132 const_iterator(iterator i): node_(i.node_) {}
133 const_reference operator*()
const
136 return static_cast<const node_t* const
>(node_)->value;
138 const_pointer operator->()
const
141 return &
static_cast<const node_t* const
>(node_)->value;
143 const_iterator& operator++() { node_ = node_->next;
return *
this; }
144 const_iterator operator++(
int) { const_iterator result(*
this); ++(*this);
return result; }
145 bool operator==(
const const_iterator& other)
const {
return node_ == other.node_; }
146 bool operator!=(
const const_iterator& other)
const {
return !(*
this == other); }
148 friend class slist<T, Alloc>;
149 explicit const_iterator(
const node_base_t* node): node_(node) {}
150 const node_base_t* node_;
153 explicit slist(
const Alloc& allocator = Alloc());
154 explicit slist(size_type n,
const T& value = T(),
const Alloc& allocator = Alloc());
155 template <
typename InputIterator>
slist(InputIterator first, InputIterator last,
156 const Alloc& allocator = Alloc());
161 template <
typename InputIterator>
void assign(InputIterator first, InputIterator last);
162 void assign(size_type n,
const T& value = T());
168 const_iterator
end()
const;
172 iterator
prior(iterator position)
const;
173 const_iterator
prior(const_iterator position)
const;
174 iterator
prior(iterator position, iterator start)
const;
175 const_iterator
prior(const_iterator position, const_iterator start)
const;
180 void resize(size_type n,
const T& value = T());
187 iterator
insert(iterator position,
const T& value);
188 void insert(iterator position, size_type n,
const T& value);
189 template <
typename InputIterator>
void insert(iterator position, InputIterator first,
194 template <
typename InputIterator>
void insert_after(iterator position, InputIterator first,
198 iterator
erase(iterator position, iterator last);
211 iterator before_last);
214 template <
class UnaryPredicate>
void remove_if(UnaryPredicate predicate);
217 template <
class BinaryPredicate>
void unique(BinaryPredicate predicate);
223 template <
class Compare>
void sort(Compare compare);
229 typedef typename std::allocator_traits<allocator_type>::template rebind_alloc<node_t> node_allocator_type;
231 node_t* make_node(
const T& value)
const;
232 void unlink_and_destroy_after(node_base_t* position)
const;
233 void link_after(node_base_t* position, node_base_t* node)
const;
234 void splice_after(node_base_t* position, node_base_t* before_first,
235 node_base_t* before_last)
const;
237 template <
typename IntegerType>
238 void insert_after(iterator position, IntegerType n, IntegerType value,
239 meta::Wrap<meta::True> parameter_is_integral);
240 template <
typename InputIterator>
void insert_after(iterator position, InputIterator first,
241 InputIterator last, meta::Wrap<meta::False> parameter_is_iterator);
246template <
typename T,
class Alloc>
248template <
typename T,
class Alloc>
250template <
typename T,
class Alloc>
252template <
typename T,
class Alloc>
254template <
typename T,
class Alloc>
256template <
typename T,
class Alloc>
259template <
typename T,
class Alloc,
typename Char,
typename Traits>
260std::basic_ostream<Char, Traits>&
261operator<<(std::basic_ostream<Char, Traits>& o_stream,
263template <
typename T,
class Alloc,
typename Char,
typename Traits>
264std::basic_istream<Char, Traits>&
265operator>>(std::basic_istream<Char, Traits>& i_stream,
a single linked list, just like the one in SGI STL (and STLport ...)
iterator erase(iterator position, iterator last)
removes element in range from the list and return iterator to the next element.
void clear()
removes all elements from the list
void splice(iterator position, slist< T, Alloc > &other, iterator first, iterator last)
moves [ first , last ) from other to *this before position without copying.
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.
const_iterator prior(const_iterator position, const_iterator start) const
return the iterator that sits position and start searching for it from start.
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.
void erase_after(iterator position, iterator last)
removes element in range from the list and return iterator to the next element.
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.
const_reference front() const
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.
iterator prior(iterator position, iterator start) const
return the iterator that sits position and start searching for it from start.
size_type size() const
returns the N, the number of elements in the list.
void splice_after(iterator position, slist< T, Alloc > &other, iterator before_x)
moves element before before_x from other to *this after position without copying.
void assign(size_type n, const T &value=T())
replace *this by a list with n copies of value
iterator erase(iterator position)
removes element at iterator position from the list and return iterator to the next element.
const_iterator before_begin() const
returns an iterator for the position before the first element of the list.
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 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 insert_after(iterator position, size_type n, const T &value)
inserts n copies of value after iterator position.
void remove(const T &value)
removes all elements with iterarors i for which *i == value
const_iterator end() const
returns an iterator for the position after the last element of the list.
void unique(BinaryPredicate predicate)
removes all but the first element in every consecutive group of equivalent elements by a predicate.
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.
void splice(iterator position, slist< T, Alloc > &other, iterator x)
moves x from other to *this before position without copying.
const_iterator prior(const_iterator position) const
return the iterator that sits position and start searching for it from start.
slist< T, Alloc > & operator=(slist< T, Alloc > other)
replace *this by a copy of other.
void merge(slist< T, Alloc > &other, BinaryPredicate compare)
Merge two by compare sorted containers to one big sorted.
iterator prior(iterator position) const
return the iterator that sits position and start searching for it from start.
slist(size_type n, const T &value=T(), const Alloc &allocator=Alloc())
Creates an list with n elements - each of which is a copy of value - and an allocator.
void pop_front()
erases the first element in the list.
slist(InputIterator first, InputIterator last, const Alloc &allocator=Alloc())
creates a list with as elements a copy of a range, and an allocator.
void insert_after(iterator position, InputIterator first, InputIterator last)
inserts a copy of a range before iterator position.
void splice_after(iterator position, slist< T, Alloc > &other, iterator before_first, iterator before_last)
moves ( before_first, before_last ] from other to *this after position without copying.
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 insert(iterator position, InputIterator first, InputIterator last)
inserts a copy of a range before iterator position.
void erase_after(iterator position)
removes element after iterator position from the list.
void swap(slist< T, Alloc > &other)
exchange all data between two lists.
void remove_if(UnaryPredicate predicate)
removes all elements with iterarors i for which predicate(*i) yields true.
const_iterator begin() const
returns an iterator to the first element of the list.
allocator_type get_allocator() const
returns the memory model of the list.
void insert(iterator position, size_type n, const T &value)
inserts n copies of value before iterator position.
void reverse()
reverses the order of the elements.
slist(const slist< T, Alloc > &other)
copies an entire list and its elements and allocator.
lass extensions to the standard library
Library for Assembled Shared Sources.