Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/forward list"

From cppreference.com
< cpp‎ | container
(update par)
m (Shorten template names. Use {{lc}} where appropriate.)
Line 8: Line 8:
 
}}  
 
}}  
  
{{tt|std::forward_list}} is a container that supports fast insertion and removal of elements from anywhere in the container. Fast random access is not supported. It is implemented as singly-linked list and essentially does not have any overhead compared to its implementation in C. Compared to {{c|std::list}} this container provides more space efficient storage when bidirectional iteration is not needed.  
+
{{tt|std::forward_list}} is a container that supports fast insertion and removal of elements from anywhere in the container. Fast random access is not supported. It is implemented as singly-linked list and essentially does not have any overhead compared to its implementation in C. Compared to {{lc|std::list}} this container provides more space efficient storage when bidirectional iteration is not needed.  
  
 
Addition, removal and moving the elements within the list or across several lists does not invalidate the iterators. An iterator is invalidated only when the corresponding element is deleted.
 
Addition, removal and moving the elements within the list or across several lists does not invalidate the iterators. An iterator is invalidated only when the corresponding element is deleted.
Line 21: Line 21:
  
 
===Member types===
 
===Member types===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list hitem | Member type | Definition}}
+
{{dsc hitem | Member type | Definition}}
{{dcl list template | cpp/container/dcl list value_type | forward_list}}
+
{{dsc inc | cpp/container/dcl list value_type | forward_list}}
{{dcl list template | cpp/container/dcl list allocator_type | forward_list}}
+
{{dsc inc | cpp/container/dcl list allocator_type | forward_list}}
{{dcl list template | cpp/container/dcl list size_type | forward_list}}
+
{{dsc inc | cpp/container/dcl list size_type | forward_list}}
{{dcl list template | cpp/container/dcl list difference_type | forward_list}}
+
{{dsc inc | cpp/container/dcl list difference_type | forward_list}}
{{dcl list template | cpp/container/dcl list reference | forward_list}}
+
{{dsc inc | cpp/container/dcl list reference | forward_list}}
{{dcl list template | cpp/container/dcl list const_reference | forward_list}}
+
{{dsc inc | cpp/container/dcl list const_reference | forward_list}}
{{dcl list template | cpp/container/dcl list pointer | forward_list}}
+
{{dsc inc | cpp/container/dcl list pointer | forward_list}}
{{dcl list template | cpp/container/dcl list const_pointer | forward_list}}
+
{{dsc inc | cpp/container/dcl list const_pointer | forward_list}}
{{dcl list template | cpp/container/dcl list iterator | forward_list}}
+
{{dsc inc | cpp/container/dcl list iterator | forward_list}}
{{dcl list template | cpp/container/dcl list const_iterator | forward_list}}
+
{{dsc inc | cpp/container/dcl list const_iterator | forward_list}}
{{dcl list end}}
+
{{dsc end}}
  
 
===Member functions===
 
===Member functions===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/container/dcl list constructor | forward_list}}
+
{{dsc inc | cpp/container/dcl list constructor | forward_list}}
{{dcl list template | cpp/container/dcl list destructor | forward_list}}
+
{{dsc inc | cpp/container/dcl list destructor | forward_list}}
{{dcl list template | cpp/container/dcl list operator{{=}} | forward_list}}
+
{{dsc inc | cpp/container/dcl list operator{{=}} | forward_list}}
{{dcl list template | cpp/container/dcl list assign | forward_list}}
+
{{dsc inc | cpp/container/dcl list assign | forward_list}}
{{dcl list template | cpp/container/dcl list get_allocator | forward_list}}
+
{{dsc inc | cpp/container/dcl list get_allocator | forward_list}}
  
{{dcl list h2 | Element access}}
+
{{dsc h2 | Element access}}
{{dcl list template | cpp/container/dcl list front | forward_list}}
+
{{dsc inc | cpp/container/dcl list front | forward_list}}
  
{{dcl list h2 | Iterators}}
+
{{dsc h2 | Iterators}}
{{dcl list template | cpp/container/dcl list before_begin | forward_list}}
+
{{dsc inc | cpp/container/dcl list before_begin | forward_list}}
{{dcl list template | cpp/container/dcl list begin | forward_list}}
+
{{dsc inc | cpp/container/dcl list begin | forward_list}}
{{dcl list template | cpp/container/dcl list end | forward_list}}
+
{{dsc inc | cpp/container/dcl list end | forward_list}}
  
{{dcl list h2 | Capacity}}
+
{{dsc h2 | Capacity}}
{{dcl list template | cpp/container/dcl list empty | forward_list}}
+
{{dsc inc | cpp/container/dcl list empty | forward_list}}
{{dcl list template | cpp/container/dcl list max_size | forward_list}}
+
{{dsc inc | cpp/container/dcl list max_size | forward_list}}
  
{{dcl list h2 | Modifiers}}
+
{{dsc h2 | Modifiers}}
{{dcl list template | cpp/container/dcl list clear | forward_list}}
+
{{dsc inc | cpp/container/dcl list clear | forward_list}}
{{dcl list template | cpp/container/dcl list insert_after | forward_list}}
+
{{dsc inc | cpp/container/dcl list insert_after | forward_list}}
{{dcl list template | cpp/container/dcl list emplace_after | forward_list}}
+
{{dsc inc | cpp/container/dcl list emplace_after | forward_list}}
{{dcl list template | cpp/container/dcl list erase_after | forward_list}}
+
{{dsc inc | cpp/container/dcl list erase_after | forward_list}}
{{dcl list template | cpp/container/dcl list push_front | forward_list}}
+
{{dsc inc | cpp/container/dcl list push_front | forward_list}}
{{dcl list template | cpp/container/dcl list emplace_front | forward_list}}
+
{{dsc inc | cpp/container/dcl list emplace_front | forward_list}}
{{dcl list template | cpp/container/dcl list pop_front | forward_list}}
+
{{dsc inc | cpp/container/dcl list pop_front | forward_list}}
{{dcl list template | cpp/container/dcl list resize | forward_list}}
+
{{dsc inc | cpp/container/dcl list resize | forward_list}}
{{dcl list template | cpp/container/dcl list swap | forward_list}}
+
{{dsc inc | cpp/container/dcl list swap | forward_list}}
  
{{dcl list h2 | Operations}}
+
{{dsc h2 | Operations}}
{{dcl list template | cpp/container/dcl list merge | forward_list}}
+
{{dsc inc | cpp/container/dcl list merge | forward_list}}
{{dcl list template | cpp/container/dcl list splice_after | forward_list}}
+
{{dsc inc | cpp/container/dcl list splice_after | forward_list}}
{{dcl list template | cpp/container/dcl list remove | forward_list}}
+
{{dsc inc | cpp/container/dcl list remove | forward_list}}
{{dcl list template | cpp/container/dcl list reverse | forward_list}}
+
{{dsc inc | cpp/container/dcl list reverse | forward_list}}
{{dcl list template | cpp/container/dcl list unique | forward_list}}
+
{{dsc inc | cpp/container/dcl list unique | forward_list}}
{{dcl list template | cpp/container/dcl list sort | forward_list}}
+
{{dsc inc | cpp/container/dcl list sort | forward_list}}
{{dcl list end}}
+
{{dsc end}}
  
 
===Non-member functions===
 
===Non-member functions===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/container/dcl list operator_cmp | forward_list}}
+
{{dsc inc | cpp/container/dcl list operator_cmp | forward_list}}
{{dcl list template | cpp/container/dcl list swap2 | forward_list}}
+
{{dsc inc | cpp/container/dcl list swap2 | forward_list}}
{{dcl list end}}
+
{{dsc end}}
  
 
[[de:cpp/container/forward list]]
 
[[de:cpp/container/forward list]]

Revision as of 18:39, 31 May 2013

 
 
 
 
Defined in header <forward_list>
template<

    class T,
    class Allocator = std::allocator<T>

> class forward_list;
(since C++11)

std::forward_list is a container that supports fast insertion and removal of elements from anywhere in the container. Fast random access is not supported. It is implemented as singly-linked list and essentially does not have any overhead compared to its implementation in C. Compared to std::list this container provides more space efficient storage when bidirectional iteration is not needed.

Addition, removal and moving the elements within the list or across several lists does not invalidate the iterators. An iterator is invalidated only when the corresponding element is deleted.

std::forward_list meets the requirements of Template:concept (except for the size() member function), Template:concept and Template:concept.

Contents

Template parameters

T - The type of the elements.
T must meet the requirements of CopyAssignable and CopyConstructible. (until C++11)
The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements. (since C++11)

[edit]

Allocator - An allocator that is used to acquire/release memory and to construct/destroy the elements in that memory. The type must meet the requirements of Allocator. The behavior is undefined(until C++20)The program is ill-formed(since C++20) if Allocator::value_type is not the same as T.[edit]

Member types

Template:cpp/container/dcl list value typeTemplate:cpp/container/dcl list allocator typeTemplate:cpp/container/dcl list size typeTemplate:cpp/container/dcl list difference typeTemplate:cpp/container/dcl list referenceTemplate:cpp/container/dcl list const referenceTemplate:cpp/container/dcl list pointerTemplate:cpp/container/dcl list const pointerTemplate:cpp/container/dcl list iteratorTemplate:cpp/container/dcl list const iterator
Member type Definition

Member functions

Template:cpp/container/dcl list constructorTemplate:cpp/container/dcl list destructorTemplate:cpp/container/dcl list operator=Template:cpp/container/dcl list assignTemplate:cpp/container/dcl list get allocatorTemplate:cpp/container/dcl list frontTemplate:cpp/container/dcl list before beginTemplate:cpp/container/dcl list beginTemplate:cpp/container/dcl list endTemplate:cpp/container/dcl list emptyTemplate:cpp/container/dcl list max sizeTemplate:cpp/container/dcl list clearTemplate:cpp/container/dcl list insert afterTemplate:cpp/container/dcl list emplace afterTemplate:cpp/container/dcl list erase afterTemplate:cpp/container/dcl list push frontTemplate:cpp/container/dcl list emplace frontTemplate:cpp/container/dcl list pop frontTemplate:cpp/container/dcl list resizeTemplate:cpp/container/dcl list swapTemplate:cpp/container/dcl list mergeTemplate:cpp/container/dcl list splice afterTemplate:cpp/container/dcl list removeTemplate:cpp/container/dcl list reverseTemplate:cpp/container/dcl list uniqueTemplate:cpp/container/dcl list sort
Element access
Iterators
Capacity
Modifiers
Operations

Non-member functions

Template:cpp/container/dcl list operator cmpTemplate:cpp/container/dcl list swap2