SourcePro® C++ API Reference Guide

Product Documentation:
   SourcePro C++
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 A implemented as a singly-linked list. More...

#include <rw/stdex/slist.h>

Public Types

typedef A::template rebind< Node >::other allocator_type
 
typedef ConstIterator const_iterator
 
typedef const T * const_pointer
 
typedef const T & const_reference
 
typedef allocator_type::difference_type difference_type
 
typedef Iterator iterator
 
typedef T * pointer
 
typedef T & reference
 
typedef allocator_type::size_type size_type
 
typedef T value_type
 

Public Member Functions

 rw_slist ()
 
 rw_slist (const rw_slist< T, A > &list)
 
 rw_slist (rw_slist< T, A > &&list)
 
template<class InputIterator >
 rw_slist (InputIterator first, InputIterator last)
 
 ~rw_slist ()
 
template<class InputIterator >
void assign (InputIterator first, InputIterator last)
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
iterator erase (const_iterator iter)
 
iterator erase (const_iterator first, const_iterator bound)
 
T & front ()
 
const T & front () const
 
iterator insert (iterator loc, const T &val)
 
iterator insert (iterator loc, T &&val)
 
template<class InputIterator >
iterator insert (iterator loc, InputIterator first, InputIterator last)
 
void merge (rw_slist< T, A > &donor)
 
rw_slist< T, A > & operator= (const rw_slist< T, A > &list)
 
rw_slist< T, A > & operator= (rw_slist< T, A > &&list)
 
void pop_front ()
 
void push_back (const T &item)
 
void push_back (T &&item)
 
void push_front (const T &item)
 
void push_front (T &&item)
 
void reverse ()
 
size_type size () const
 
void sort ()
 
void splice (iterator to, rw_slist< T, A > &donor)
 
void splice (iterator to, rw_slist< T, A > &donor, iterator from)
 
void splice (iterator to, rw_slist< T, A > &donor, iterator from_start, iterator from_bound)
 
void swap (rw_slist< T, A > &other)
 
void unique ()
 

Related Functions

(Note that these are not member functions.)

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

Detailed Description

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

Class rw_slist<T,A> 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<T,A> provides for iterators that reference its elements. Operations that alter the contents of rw_slist<T,A> invalidate iterators that reference items at or after the location of change.

Synopsis
#include <rw/stdex/slist.h>

Member Typedef Documentation

template<class T, class A = std::allocator<T>>
typedef A::template rebind<Node>::other rw_slist< T, A >::allocator_type

A type representing the allocator type for the container.

template<class T, class A = std::allocator<T>>
typedef ConstIterator rw_slist< T, A >::const_iterator

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

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

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

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

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

template<class T, class A = std::allocator<T>>
typedef 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<class T, class A = std::allocator<T>>
typedef Iterator rw_slist< T, A >::iterator

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

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

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

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

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

template<class T, class A = std::allocator<T>>
typedef 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<class T, class A = std::allocator<T>>
typedef T rw_slist< T, A >::value_type

A type representing the container's data type.

Constructor & Destructor Documentation

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

Constructs an empty rw_slist<T,A> .

template<class T, class A = std::allocator<T>>
rw_slist< T, A >::rw_slist ( const rw_slist< T, A > &  list)

Constructs an rw_slist<T,A> that is a copy of list. Each element from list is copied into self.

template<class T, class A = std::allocator<T>>
rw_slist< T, A >::rw_slist ( rw_slist< T, A > &&  list)

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

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

Constructs an rw_slist<T,A> 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<class T, class A = std::allocator<T>>
rw_slist< T, A >::~rw_slist ( )

The destructor releases the memory used by the links.

Member Function Documentation

template<class T, class A = std::allocator<T>>
template<class InputIterator >
void rw_slist< T, A >::assign ( InputIterator  first,
InputIterator  last 
)

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

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

Note
first and last must not be iterators into self.
template<class T, class A = std::allocator<T>>
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<class T, class A = std::allocator<T>>
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<class T, class A = std::allocator<T>>
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 end().

template<class T, class A = std::allocator<T>>
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<class T, class A = std::allocator<T>>
bool rw_slist< T, A >::empty ( ) const
inline

Returns true if self is empty.

template<class T, class A = std::allocator<T>>
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<class T, class A = std::allocator<T>>
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<class T, class A = std::allocator<T>>
iterator rw_slist< T, A >::erase ( const_iterator  iter)

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

template<class T, class A = std::allocator<T>>
iterator rw_slist< T, A >::erase ( const_iterator  first,
const_iterator  bound 
)

Removes from self the elements referenced by the range beginning at first and bounded by bound. Returns an iterator referencing a position just after the last erased item. If first does not reference an item in self (and if first and bound are not equal), the effect is undefined.

template<class T, class A = std::allocator<T>>
T& rw_slist< T, A >::front ( void  )
inline

References the first item in the list as an L-value. If self is empty, the behavior is undefined.

template<class T, class A = std::allocator<T>>
const T& rw_slist< T, A >::front ( void  ) const
inline

References the first item in the list as an L-value. If self is empty, the behavior is undefined.

template<class T, class A = std::allocator<T>>
iterator rw_slist< T, A >::insert ( iterator  loc,
const T &  val 
)

Inserts val just prior to the place referenced by loc. Returns an iterator referencing the newly inserted element.

Note
++(list.insert(loc,val)) == loc
template<class T, class A = std::allocator<T>>
iterator rw_slist< T, A >::insert ( iterator  loc,
T &&  val 
)

Inserts val just prior to the place referenced by loc. Returns an iterator referencing the newly inserted element.

Note
++(list.insert(loc,val)) == loc
Condition:
This method is only available on platforms with rvalue reference support.
template<class T, class A = std::allocator<T>>
template<class InputIterator >
iterator rw_slist< T, A >::insert ( iterator  loc,
InputIterator  first,
InputIterator  last 
)
inline

Inserts a copy of each item in the range [first, last) into self just prior to the place referenced by loc. 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
first and last must not be iterators into self.
template<class T, class A = std::allocator<T>>
void rw_slist< T, A >::merge ( rw_slist< T, A > &  donor)

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

template<class T, class A = std::allocator<T>>
rw_slist<T, A>& rw_slist< T, A >::operator= ( const rw_slist< T, A > &  list)

Copy assignment. Constructs an rw_slist<T,A> containing a copy of each element in list.

template<class T, class A = std::allocator<T>>
rw_slist<T, A>& rw_slist< T, A >::operator= ( rw_slist< T, A > &&  list)

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

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

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

template<class T, class A = std::allocator<T>>
void rw_slist< T, A >::push_back ( const T &  item)
inline

Inserts item as the last element of the list.

template<class T, class A = std::allocator<T>>
void rw_slist< T, A >::push_back ( T &&  item)
inline

Inserts item as the last element of the list.

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

Inserts item as the first element of the list.

template<class T, class A = std::allocator<T>>
void rw_slist< T, A >::push_front ( T &&  item)
inline

Inserts item as the first element of the list.

Condition:
This method is only available on platforms with rvalue reference support.
template<class T, class A = std::allocator<T>>
void rw_slist< T, A >::reverse ( )

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

template<class T, class A = std::allocator<T>>
size_type rw_slist< T, A >::size ( ) const
inline

Returns the number of items currently held in self.

template<class T, class 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 items exchanged during the sort, but adjusts the order of the links in the list.

template<class T, class A = std::allocator<T>>
void rw_slist< T, A >::splice ( iterator  to,
rw_slist< T, A > &  donor 
)
inline

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

template<class T, class A = std::allocator<T>>
void rw_slist< T, A >::splice ( iterator  to,
rw_slist< T, A > &  donor,
iterator  from 
)

Removes from donor and inserts into self, just before location to, the item referenced by from. If from does not reference an actual item contained in donor the effect is undefined. This method does not copy or destroy the item referenced by from, but re-links the node containing it from donor into self.

template<class T, class A = std::allocator<T>>
void rw_slist< T, A >::splice ( iterator  to,
rw_slist< T, A > &  donor,
iterator  from_start,
iterator  from_bound 
)

Removes from donor and inserts into self just before location to, the items referenced by the range beginning with from_start and bounded by from_bound. If that range does not refer to items contained by donor, the effect is undefined. This method does not copy or destroy the items referenced by the range, but re-links those list nodes from donor into self.

template<class T, class A = std::allocator<T>>
void rw_slist< T, A >::swap ( rw_slist< T, A > &  other)

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

template<class T, class 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<class T , class A >
bool operator!= ( const rw_slist< T, A > &  lhs,
const rw_slist< T, A > &  rhs 
)
related

Equivalent to !(lhs == rhs).

template<class T , class 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<class T , class A >
bool operator<= ( const rw_slist< T, A > &  lhs,
const rw_slist< T, A > &  rhs 
)
related

Equivalent to !(rhs < lhs).

template<class T , class 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<class T , class A >
bool operator> ( const rw_slist< T, A > &  lhs,
const rw_slist< T, A > &  rhs 
)
related

Equivalent to (rhs < lhs).

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

Equivalent to !(lhs < rhs).

Copyright © 2015 Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.