SourcePro® API Reference Guide

Product Documentation:
   SourcePro
Documentation Home
List of all members | Public Types | Public Member Functions | Related Functions
rw_slist< T, A > Class Template Reference

Maintains a collection of some type T implemented as a singly-linked list. More...

#include <rw/stdex/slist.h>

Public Types

typedef std::allocator_traits< A >::template rebind_alloc< node_type > allocator_type
 
typedef rw_slist_iterator_base< const T, const base_node_type, difference_typeconst_iterator
 
typedef const value_typeconst_pointer
 
typedef const value_typeconst_reference
 
typedef std::allocator_traits< allocator_type >::difference_type difference_type
 
typedef rw_slist_iterator_base< T, base_node_type, difference_typeiterator
 
typedef value_typepointer
 
typedef value_typereference
 
typedef std::allocator_traits< allocator_type >::size_type size_type
 
typedef T value_type
 

Public Member Functions

 rw_slist ()
 
 rw_slist (const rw_slist< T, A > &x)
 
 rw_slist (rw_slist< T, A > &&x)
 
template<typename InputIterator >
 rw_slist (InputIterator first, InputIterator last)
 
 rw_slist (size_type n, const T &value)
 
 ~rw_slist ()
 
template<typename InputIterator >
void assign (InputIterator first, InputIterator last)
 
reference back ()
 
const_reference back () const
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear ()
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
iterator erase (const_iterator position)
 
iterator erase (const_iterator position, const_iterator last)
 
reference front ()
 
const_reference front () const
 
iterator insert (iterator position, const T &x)
 
iterator insert (iterator position, T &&x)
 
template<typename InputIterator >
iterator insert (iterator position, InputIterator first, InputIterator last)
 
iterator insert (iterator position, size_type n, const T &value)
 
size_type max_size () const
 
void merge (rw_slist< T, A > &x)
 
rw_slist< T, A > & operator= (const rw_slist< T, A > &x)
 
rw_slist< T, A > & operator= (rw_slist< T, A > &&x)
 
void pop_front ()
 
void push_back (const T &x)
 
void push_back (T &&x)
 
void push_front (const T &x)
 
void push_front (T &&x)
 
void remove (const T &value)
 
void reverse ()
 
size_type size () const
 
void sort ()
 
void splice (iterator position, rw_slist< T, A > &x)
 
void splice (iterator position, rw_slist< T, A > &x, iterator i)
 
void splice (iterator position, rw_slist< T, A > &x, iterator first, iterator last)
 
void swap (rw_slist< T, A > &x)
 
void unique ()
 

Related Functions

(Note that these are not member functions.)

template<typename T , typename A >
bool operator!= (const rw_slist< T, A > &lhs, const rw_slist< T, A > &rhs)
 
template<typename T , typename A >
bool operator< (const rw_slist< T, A > &lhs, const rw_slist< T, A > &rhs)
 
template<typename T , typename A >
bool operator<= (const rw_slist< T, A > &lhs, const rw_slist< T, A > &rhs)
 
template<typename T , typename A >
bool operator== (const rw_slist< T, A > &lhs, const rw_slist< T, A > &rhs)
 
template<typename T , typename A >
bool operator> (const rw_slist< T, A > &lhs, const rw_slist< T, A > &rhs)
 
template<typename T , typename A >
bool operator>= (const rw_slist< T, A > &lhs, const rw_slist< T, A > &rhs)
 

Detailed Description

template<typename T, typename A = std::allocator<T>>
class rw_slist< T, A >

Class rw_slist maintains a collection of T, implemented as a singly-linked list. Since this is a value-based list, objects are copied into and out of the links that make up the list. As with all classes that meet the ANSI sequence specification, rw_slist provides for iterators that reference its elements.

Note
Unlike std::list and std::forward_list, operations that alter the contents of rw_slist invalidate iterators that reference elements at or after the location of change.

Member Typedef Documentation

template<typename T, typename A = std::allocator<T>>
typedef std::allocator_traits<A>::template rebind_alloc<node_type> rw_slist< T, A >::allocator_type

A type representing the allocator type for the container.

template<typename T, typename A = std::allocator<T>>
typedef rw_slist_iterator_base<const T, const base_node_type, difference_type> rw_slist< T, A >::const_iterator

A type that provides a const forward iterator over the elements in the container.

template<typename T, typename A = std::allocator<T>>
typedef const value_type* rw_slist< T, A >::const_pointer

A type that provides a const pointer to an element in the container.

template<typename T, typename A = std::allocator<T>>
typedef const value_type& rw_slist< T, A >::const_reference

A type that provides a const reference to an element in the container.

template<typename T, typename A = std::allocator<T>>
typedef std::allocator_traits<allocator_type>::difference_type rw_slist< T, A >::difference_type

A signed integral type used to indicate the distance between two valid iterators on the same container.

template<typename T, typename A = std::allocator<T>>
typedef rw_slist_iterator_base<T, base_node_type, difference_type> rw_slist< T, A >::iterator

A type that provides a forward iterator over the elements in the container.

template<typename T, typename A = std::allocator<T>>
typedef value_type* rw_slist< T, A >::pointer

A type that provides a pointer to an element in the container.

template<typename T, typename A = std::allocator<T>>
typedef value_type& rw_slist< T, A >::reference

A type that provides a reference to an element in the container.

template<typename T, typename A = std::allocator<T>>
typedef std::allocator_traits<allocator_type>::size_type rw_slist< T, A >::size_type

An unsigned integral type used for counting the number of elements in the container.

template<typename T, typename A = std::allocator<T>>
typedef T rw_slist< T, A >::value_type

A type representing the value stored in the container.

Constructor & Destructor Documentation

template<typename T , typename A >
rw_slist< T, A >::rw_slist ( )
inline

Constructs an empty rw_slist.

template<typename T, typename A>
rw_slist< T, A >::rw_slist ( const rw_slist< T, A > &  x)
inline

Constructs an rw_slist that is a copy of x. Each element from x is copied into self.

template<typename T, typename A>
rw_slist< T, A >::rw_slist ( rw_slist< T, A > &&  x)
inline

Move constructor. The constructed list takes ownership of the data owned by x.

Condition:
This method is available only on platforms with rvalue reference support.
template<typename T, typename A = std::allocator<T>>
template<typename InputIterator >
rw_slist< T, A >::rw_slist ( InputIterator  first,
InputIterator  last 
)

Constructs an rw_slist containing a copy of each element in the range [first, last).

InputIterator is an input iterator type that points to elements that are convertible to value_type objects.

template<typename T, typename A>
rw_slist< T, A >::rw_slist ( size_type  n,
const T &  value 
)
inline

Constructs an rw_slist containing n instances of value.

template<typename T , typename A >
rw_slist< T, A >::~rw_slist ( )
inline

The destructor releases the memory used by the links.

Member Function Documentation

template<typename T , typename A >
template<typename InputIterator >
void rw_slist< T, A >::assign ( InputIterator  first,
InputIterator  last 
)
inline

Copies each element in the range [first, last) into self, replacing any existing elements.

InputIterator is an input iterator type that points to elements that are convertible to value_type objects.

Note
If first or last are iterators into this container, the behavior is undefined.
template<typename T , typename A >
rw_slist< T, A >::reference rw_slist< T, A >::back ( )
inline

Returns a reference to the last element in self. If self is empty, the behavior is undefined.

template<typename T , typename A >
rw_slist< T, A >::const_reference rw_slist< T, A >::back ( ) const
inline

Returns a const_reference to the last element in self. If self is empty, the behavior is undefined.

template<typename T , typename A >
rw_slist< T, A >::iterator rw_slist< T, A >::begin ( )
inline

Returns an iterator referring to the first element in the container.

If the container is empty, returns end().

template<typename T , typename A >
rw_slist< T, A >::const_iterator rw_slist< T, A >::begin ( ) const
inline

Returns an iterator referring to the first element in the container.

If the container is empty, returns end().

template<typename T , typename A >
rw_slist< T, A >::const_iterator rw_slist< T, A >::cbegin ( ) const
inline

Returns an iterator referring to the first element in the container.

If the container is empty, returns cend().

template<typename T , typename A >
rw_slist< T, A >::const_iterator rw_slist< T, A >::cend ( ) const
inline

Returns an iterator referring to the element after the last element in the container.

Dereferencing the iterator returned by this function results in undefined behavior.

template<typename T , typename A >
void rw_slist< T, A >::clear ( )
inline

Removes all elements from self.

template<typename T , typename A >
bool rw_slist< T, A >::empty ( ) const
inline

Returns true if self is empty.

template<typename T , typename A >
rw_slist< T, A >::iterator rw_slist< T, A >::end ( )
inline

Returns an iterator referring to the element after the last element in the container.

Dereferencing the iterator returned by this function results in undefined behavior.

template<typename T , typename A >
rw_slist< T, A >::const_iterator rw_slist< T, A >::end ( ) const
inline

Returns an iterator referring to the element after the last element in the container.

Dereferencing the iterator returned by this function results in undefined behavior.

template<typename T, typename A = std::allocator<T>>
iterator rw_slist< T, A >::erase ( const_iterator  position)

Removes from self the element referenced by position. If position does not reference an actual element contained in self, the behavior is undefined. Returns an iterator referencing the location just after the erased element.

template<typename T, typename A = std::allocator<T>>
iterator rw_slist< T, A >::erase ( const_iterator  position,
const_iterator  last 
)

Removes from self the elements referenced by the range beginning at position and bounded by last. Returns an iterator referencing a position just after the last erased element. If position does not reference an element in self the behavior is undefined.

template<typename T , typename A >
rw_slist< T, A >::reference rw_slist< T, A >::front ( )
inline

Returns a reference to the first element in self. If self is empty, the behavior is undefined.

template<typename T , typename A >
rw_slist< T, A >::const_reference rw_slist< T, A >::front ( ) const
inline

Returns a const_reference to the first element in self. If self is empty, the behavior is undefined.

template<typename T, typename A = std::allocator<T>>
iterator rw_slist< T, A >::insert ( iterator  position,
const T &  x 
)

Inserts x just prior to the element referenced by position. Returns an iterator referencing the newly inserted element.

template<typename T, typename A = std::allocator<T>>
iterator rw_slist< T, A >::insert ( iterator  position,
T &&  x 
)

Inserts x just prior to the element referenced by position. Returns an iterator referencing the newly inserted element.

Condition:
This method is available only on platforms with rvalue reference support.
template<typename T, typename A = std::allocator<T>>
template<typename InputIterator >
iterator rw_slist< T, A >::insert ( iterator  position,
InputIterator  first,
InputIterator  last 
)

Inserts a copy of each element in the range [first, last) into self just prior to the element referenced by position. Returns an iterator referencing the first newly inserted element.

InputIterator is an input iterator type that points to elements that are convertible to value_type objects.

Note
If first or last are iterators into this container, the behavior is undefined.
template<typename T, typename A = std::allocator<T>>
iterator rw_slist< T, A >::insert ( iterator  position,
size_type  n,
const T &  value 
)

Inserts n copies of value into self prior to the element referenced by position. Returns an iterator to the first of the newly inserted elements.

template<typename T , typename A >
rw_slist< T, A >::size_type rw_slist< T, A >::max_size ( ) const
inline

Returns the maximum number of elements the container could hold.

Note
This is a theoretical limit. The actual limit may be constrained by system resources.
template<typename T, typename A = std::allocator<T>>
void rw_slist< T, A >::merge ( rw_slist< T, A > &  x)

Assuming both x and self are sorted, moves every element from x into self, leaving x empty, and self sorted. If either list is unsorted, the move takes place, but the result may not be sorted. This method does not copy or destroy the elements in x, but re-links list nodes into self.

template<typename T, typename A>
rw_slist< T, A > & rw_slist< T, A >::operator= ( const rw_slist< T, A > &  x)
inline

Copy assignment. Constructs an rw_slist containing a copy of each element in x.

template<typename T, typename A>
rw_slist< T, A > & rw_slist< T, A >::operator= ( rw_slist< T, A > &&  x)
inline

Move assignment. Self takes ownership of the data owned by x.

Condition:
This method is available only on platforms with rvalue reference support.
template<typename T , typename A >
void rw_slist< T, A >::pop_front ( )
inline

Erases the first element of self. If self is empty, the behavior is undefined.

template<typename T, typename A >
void rw_slist< T, A >::push_back ( const T &  x)
inline

Inserts x as the last element of the list.

template<typename T, typename A >
void rw_slist< T, A >::push_back ( T &&  x)
inline

Inserts x as the last element of the list.

Condition:
This method is available only on platforms with rvalue reference support.
template<typename T, typename A >
void rw_slist< T, A >::push_front ( const T &  x)
inline

Inserts x as the first element of the list.

template<typename T, typename A >
void rw_slist< T, A >::push_front ( T &&  x)
inline

Inserts x as the first element of the list.

Condition:
This method is available only on platforms with rvalue reference support.
template<typename T, typename A = std::allocator<T>>
void rw_slist< T, A >::remove ( const T &  value)

Removes all elements in self that compare equal (T::operator==() or equivalent) to value.

template<typename T, typename A = std::allocator<T>>
void rw_slist< T, A >::reverse ( )

Reverses the order of the nodes containing the elements in self.

template<typename T , typename A >
rw_slist< T, A >::size_type rw_slist< T, A >::size ( ) const
inline

Returns the number of elements currently held in self.

template<typename T, typename A = std::allocator<T>>
void rw_slist< T, A >::sort ( )

Sorts self according to T::operator<(T) or equivalent. Runs in time proportional to N log(N), where N is the number of elements. This method does not copy or destroy any of the elements exchanged during the sort, but adjusts the order of the links in the list.

template<typename T, typename A = std::allocator<T>>
void rw_slist< T, A >::splice ( iterator  position,
rw_slist< T, A > &  x 
)

Inserts the entire contents of x into self, just before the element referenced by position, leaving x empty. This method does not copy or destroy any of the elements moved, but re-links the list nodes from x into self.

template<typename T, typename A = std::allocator<T>>
void rw_slist< T, A >::splice ( iterator  position,
rw_slist< T, A > &  x,
iterator  i 
)

Inserts the element referenced by i into self, just before the element referenced by position. The element referenced by i is removed from x. This method does not copy or destroy the element moved, but re-links the node from x into self. If i is not an iterator into x, the behavior is undefined.

template<typename T, typename A = std::allocator<T>>
void rw_slist< T, A >::splice ( iterator  position,
rw_slist< T, A > &  x,
iterator  first,
iterator  last 
)

Inserts the elements in the range [first, last) just before the element referenced by position. The elements in the range [first, last) are removed from x. This method does not copy or destroy any of the elements moved, but re-links the list nodes from x into self. If i is not an iterator into x, the behavior is undefined.

template<typename T, typename A>
void rw_slist< T, A >::swap ( rw_slist< T, A > &  x)
inline

Exchanges the contents of self with x, retaining the ordering of each. This method does not copy or destroy any of the elements exchanged, but re-links the lists.

template<typename T, typename A = std::allocator<T>>
void rw_slist< T, A >::unique ( )

Removes from self all but the first element from each equal range. A precondition is that any duplicate elements are adjacent.

Friends And Related Function Documentation

template<typename T , typename A >
bool operator!= ( const rw_slist< T, A > &  lhs,
const rw_slist< T, A > &  rhs 
)
related

Equivalent to !(lhs == rhs).

template<typename T , typename A >
bool operator< ( const rw_slist< T, A > &  lhs,
const rw_slist< T, A > &  rhs 
)
related

Returns the result of calling:

lexicographical_compare(lhs.begin(), lhs.end(),
rhs.begin(), rhs.end());
template<typename T , typename A >
bool operator<= ( const rw_slist< T, A > &  lhs,
const rw_slist< T, A > &  rhs 
)
related

Equivalent to !(rhs < lhs).

template<typename T , typename A >
bool operator== ( const rw_slist< T, A > &  lhs,
const rw_slist< T, A > &  rhs 
)
related

Returns true if lhs and rhs have the same number of elements and each element of rhs tests equal (T::operator==() or equivalent) to the corresponding element of lhs.

template<typename T , typename A >
bool operator> ( const rw_slist< T, A > &  lhs,
const rw_slist< T, A > &  rhs 
)
related

Equivalent to (rhs < lhs).

template<typename T , typename A >
bool operator>= ( const rw_slist< T, A > &  lhs,
const rw_slist< T, A > &  rhs 
)
related

Equivalent to !(lhs < rhs).

Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.