SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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 (const rw_slist< T, A > &x)
 
template<typename InputIterator >
 rw_slist (InputIterator first, InputIterator last)
 
 rw_slist (rw_slist< T, A > &&x)
 
 rw_slist (size_type n, const T &value)
 
 rw_slist (void)
 
 ~rw_slist (void)
 
template<typename InputIterator >
void assign (InputIterator first, InputIterator last)
 
reference back (void)
 
const_reference back (void) const
 
iterator begin (void)
 
const_iterator begin (void) const
 
const_iterator cbegin (void) const
 
const_iterator cend (void) const
 
void clear (void)
 
bool empty (void) const
 
iterator end (void)
 
const_iterator end (void) const
 
iterator erase (const_iterator position)
 
iterator erase (const_iterator position, const_iterator last)
 
reference front (void)
 
const_reference front (void) const
 
iterator insert (iterator position, const T &x)
 
template<typename InputIterator >
iterator insert (iterator position, InputIterator first, InputIterator last)
 
iterator insert (iterator position, size_type n, const T &value)
 
iterator insert (iterator position, T &&x)
 
size_type max_size (void) 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)
 
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 (void) const
 
void sort ()
 
void splice (iterator position, rw_slist< T, A > &x)
 
void splice (iterator position, rw_slist< T, A > &x, iterator first, iterator last)
 
void splice (iterator position, rw_slist< T, A > &x, iterator i)
 
void swap (rw_slist< T, A > &x)
 
void unique ()
 

Related Symbols

(Note that these are not member symbols.)

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

◆ allocator_type

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.

◆ const_iterator

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.

◆ const_pointer

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.

◆ const_reference

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.

◆ difference_type

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.

◆ iterator

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.

◆ pointer

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.

◆ reference

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.

◆ size_type

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.

◆ value_type

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

◆ rw_slist() [1/5]

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

Constructs an empty rw_slist.

◆ rw_slist() [2/5]

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.

◆ rw_slist() [3/5]

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.

◆ rw_slist() [4/5]

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.

◆ rw_slist() [5/5]

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.

◆ ~rw_slist()

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

The destructor releases the memory used by the links.

Member Function Documentation

◆ assign()

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.

◆ back() [1/2]

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

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

◆ back() [2/2]

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

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

◆ begin() [1/2]

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

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

If the container is empty, returns end().

◆ begin() [2/2]

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

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

If the container is empty, returns end().

◆ cbegin()

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

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

If the container is empty, returns cend().

◆ cend()

template<typename T , typename A >
rw_slist< T, A >::const_iterator rw_slist< T, A >::cend ( void ) 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.

◆ clear()

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

Removes all elements from self.

◆ empty()

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

Returns true if self is empty.

◆ end() [1/2]

template<typename T , typename A >
rw_slist< T, A >::iterator rw_slist< T, A >::end ( void )
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.

◆ end() [2/2]

template<typename T , typename A >
rw_slist< T, A >::const_iterator rw_slist< T, A >::end ( void ) 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.

◆ erase() [1/2]

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.

◆ erase() [2/2]

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.

◆ front() [1/2]

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

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

◆ front() [2/2]

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

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

◆ insert() [1/4]

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.

◆ insert() [2/4]

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.

◆ insert() [3/4]

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.

◆ insert() [4/4]

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.

◆ max_size()

template<typename T , typename A >
rw_slist< T, A >::size_type rw_slist< T, A >::max_size ( void ) 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.

◆ merge()

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.

◆ operator=() [1/2]

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.

◆ operator=() [2/2]

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.

◆ pop_front()

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

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

◆ push_back() [1/2]

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.

◆ push_back() [2/2]

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.

◆ push_front() [1/2]

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.

◆ push_front() [2/2]

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.

◆ remove()

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.

◆ reverse()

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.

◆ size()

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

Returns the number of elements currently held in self.

◆ sort()

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.

◆ splice() [1/3]

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.

◆ splice() [2/3]

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.

◆ splice() [3/3]

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.

◆ swap()

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.

◆ unique()

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 Symbol Documentation

◆ operator!=()

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

Equivalent to !(lhs == rhs).

◆ operator<()

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());

◆ operator<=()

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

Equivalent to !(rhs < lhs).

◆ operator==()

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.

◆ operator>()

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

Equivalent to (rhs < lhs).

◆ operator>=()

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 © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.