18 #ifndef SINGLY_LINKED_LIST_H 19 #define SINGLY_LINKED_LIST_H 21 #define HAVE_FORWARD_LIST 1 23 #ifndef SHEAF_DLL_SPEC_H 29 #ifdef HAVE_FORWARD_LIST 30 #include <forward_list> 44 template<
class T,
class Alloc >
48 template<
class T,
class Alloc >
49 bool operator<( const singly_linked_list<T,Alloc>& lhs,
61 template <
typename T,
class A = list_ns::allocator<T> >
72 #ifdef HAVE_FORWARD_LIST 73 typedef typename list_ns::forward_list<T, A>::value_type value_type;
74 typedef typename list_ns::forward_list<T, A>::size_type
size_type;
75 typedef typename list_ns::forward_list<T, A>::difference_type
difference_type;
76 typedef typename list_ns::forward_list<T, A>::reference reference;
77 typedef typename list_ns::forward_list<T, A>::const_reference const_reference;
78 typedef typename list_ns::forward_list<T, A>::pointer pointer;
79 typedef typename list_ns::forward_list<T, A>::iterator iterator;
80 typedef typename list_ns::forward_list<T, A>::const_iterator const_iterator;
82 typedef typename list_ns::slist<T, A>::value_type value_type;
83 typedef typename list_ns::slist<T, A>::size_type
size_type;
85 typedef typename list_ns::slist<T, A>::reference reference;
86 typedef typename list_ns::slist<T, A>::const_reference const_reference;
87 typedef typename list_ns::slist<T, A>::pointer pointer;
88 typedef typename list_ns::slist<T, A>::iterator iterator;
89 typedef typename list_ns::slist<T, A>::const_iterator const_iterator;
113 : _list(count, value)
162 _list.swap(other._list);
170 return _list.front();
178 return _list.front();
186 return _list.begin();
194 return _list.begin();
210 const_iterator
end()
const 220 return _list.empty();
229 return _list.max_size();
240 #ifdef HAVE_FORWARD_LIST 254 return _list.insert_after(pos, value);
262 return _list.insert_after(pos, value);
270 _list.insert_after(pos, count, value);
277 template<
class InputIt>
280 _list.insert_after(pos, first, last);
292 return _list.erase_after(position);
295 #else // HAVE_FORWARD_LIST 304 iterator insert_after(iterator pos,
const T& value)
306 return _list.insert_after(pos, value);
312 iterator insert_after(iterator pos, T& value)
314 return _list.insert_after(pos, value);
320 void insert_after(iterator pos, size_type count,
const T& value)
322 _list.insert_after(pos, count, value);
329 template<
class InputIt>
330 void insert_after(iterator pos, InputIt first, InputIt last)
332 _list.insert_after(pos, first, last);
338 iterator erase_after(iterator position)
340 return _list.erase_after(position);
343 #endif // HAVE_FORWARD_LIST 350 _list.push_front(value);
358 _list.push_front(value);
364 template<
class InputIt>
367 #ifdef HAVE_FORWARD_LIST 368 _list.insert_after(_list.before_begin(), first, last);
370 _list.insert(_list.begin(), first, last);
395 void resize(size_type count,
const value_type& value)
397 _list.resize(count, value);
406 _list.merge(other._list);
413 void remove(
const T& value)
444 #ifdef HAVE_FORWARD_LIST 445 list_ns::forward_list<T, A> _list;
447 list_ns::slist<T, A> _list;
457 template<
class T,
class Alloc >
461 return (lhs._list == rhs._list);
464 template<
class T,
class Alloc >
465 bool operator<( const singly_linked_list<T,Alloc>& lhs,
468 return (lhs._list < rhs._list);
473 #endif // SINGLY_LINKED_LIST_H void resize(size_type count)
Resizes the container to contain count elements. Additional value-initialized elements are appended...
void merge(singly_linked_list &other)
Merges two sorted lists into one. The lists should be sorted into ascending order.
void insert_after(const_iterator pos, InputIt first, InputIt last)
inserts elements from range [first, last) after the element pointed to by pos.
void resize(size_type count, const value_type &value)
Resizes the container to contain count elements. Additional copies of value are appended.
singly_linked_list(size_type count)
Constructs the container with count value-initialized (default constructed, for classes) instances of...
bool empty() const
Checks if the container has no elements, i.e. whether begin() == end().
const_iterator begin() const
Returns an iterator to the first element of the container.
long difference_type
A signed integral type used to represent the difference of two indices or iterators.
iterator insert_after(const_iterator pos, T &&value)
Inserts value after the element pointed to by pos.
iterator erase_after(const_iterator position)
Removes the element following pos.
reference front()
Returns a reference to the first element in the container.
~singly_linked_list()
Destructor.
void push_front(InputIt first, InputIt last)
Prepends the range [first, last) to the beginning of the containter.
iterator begin()
Returns an iterator to the first element of the container.
void insert_after(const_iterator pos, size_type count, const T &value)
Inserts count copies of the value after the element pointed to by pos.
const_iterator end() const
Returns an iterator to the element following the last element of the container.
void pop_front()
Removes the first element of the container.
size_type max_size() const
Returns the maximum number of elements the container is able to hold due to system or library impleme...
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
singly_linked_list & operator=(const singly_linked_list &other)
Copy assignment operator. Replaces the contents with a copy of the contents of other.
singly_linked_list(size_type count, const T &value)
Constructs the container with count copies of elements with value value.
iterator end()
Returns an iterator to the element following the last element of the container.
singly_linked_list & operator=(singly_linked_list &other)
Move assignment operator. Replaces the contents with those of other using move semantics (i...
const_reference front() const
Returns a reference to the first element in the container.
bool operator==(const singly_linked_list< T, Alloc > &lhs, const singly_linked_list< T, Alloc > &rhs)
Checks if the contents of lhs and rhs are equal, that is, whether lhs.size() == rhs.size() and each element in lhs compares equal with the element in rhs at the same position.
void push_front(const T &value)
Prepends the given element value to the beginning of the container.
singly_linked_list(const singly_linked_list &other)
Copy Constructor.
void swap(singly_linked_list &other)
Echanges the contents of the container with those of other. Does not invoke any move, copy, or swap operations on individual elements.
void clear()
Removes all elements from the container.
void sort()
Sorts the elements in ascending order.
Namespace for the sheaves component of the sheaf system.
iterator insert_after(const_iterator pos, const T &value)
Inserts value after the element pointed to by pos.
Interface for class sheaf_dll_spec.
void push_front(T &value)
Prepends the given element value to the beginning of the container.
void unique()
Removes all consecutive duplicate elements from the container.
Wrapper class for forward_list or slist depending on compiler. The class replicates the minimum subse...
singly_linked_list()
Default Constructor.
void reverse()
Reverses the order of the elements in the container.