Forward_list Flashcards
Element access
front( )
access the first element
Parameters
(none)
Return value
reference to the first element
Complexity
Constant
Iterators
before_begin
cbefore_begin( )
returns an iterator to the element before beginning
Parameters
(none)
Return value
Iterator to the element before the first element.
Complexity
Constant.
Iterators
begin
cbegin( )
returns an iterator to the beginning
Parameters
(none)
Return value
Iterator to the first element.
Complexity
Constant.
Iterators
end
cend( )
returns an iterator to the end
Parameters
(none)
Return value
Iterator to the element following the last element.
Complexity
Constant.
Capacity
empty( )
checks whether the container is empty
Parameters
(none)
Return value
true if the container is empty, false otherwise
Complexity
Constant.
Capacity
max_size( )
returns the maximum possible number of elements
Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container.
Parameters
(none)
Return value
Maximum number of elements.
Complexity
Constant.
Modifiers
clear( )
clears the contents
Parameters
(none)
Return value (none)
Complexity
Linear in the size of the container, i.e., the number of elements.
Modifiers
insert_after( )
inserts elements after an element
Parameters
pos - iterator after which the content will be inserted
value - element value to insert
count - number of copies to insert
first, last - the range of elements to insert
ilist - initializer list to insert the values from
Type requirements
-InputIt must meet the requirements of LegacyInputIterator.
Return value
1-2) Iterator to the inserted element.
3) Iterator to the last element inserted, or pos if count==0.
4) Iterator to the last element inserted, or pos if first==last.
5) Iterator to the last element inserted, or pos if ilist is empty.
Exceptions
If an exception is thrown during insert_after there are no effects (strong exception guarantee).
Complexity 1-2) Constant. 3) Linear in count 4) Linear in std::distance(first, last) 5) Linear in ilist.size()
Modifiers
emplace_after( )
constructs elements in-place after an element
Parameters
pos - iterator after which the new element will be constructed
args - arguments to forward to the constructor of the element
Return value
iterator to the new element.
Complexity
Constant.
Exceptions
If an exception is thrown (e.g. by the constructor), the container is left unmodified, as if this function was never called (strong exception guarantee).
Modifiers
erase_after( )
erases an element after an element
Parameters
pos - iterator to the element preceding the element to remove
first, last - range of elements to remove
Return value
1) Iterator to the element following the erased one, or end() if no such element exists.
2) last
Complexity
1) Constant.
2) Linear in distance between first and last.
Modifiers
push_front( )
inserts an element to the beginning Parameters value - the value of the element to prepend Return value (none)
Complexity
Constant.
Modifiers
emplace_front( )
constructs an element in-place at the beginning
Parameters
args - arguments to forward to the constructor of the element
Type requirements
-T (the container’s element type) must meet the requirements of EmplaceConstructible.
Return value
(none) (until C++17)
A reference to the inserted element. (since C++17)
Complexity
Constant.
Modifiers
pop_front( )
removes the first element
Parameters
(none)
Return value (none)
Complexity
Constant.
Modifiers
resize( )
changes the number of elements stored
Parameters
count - new size of the container
value - the value to initialize the new elements with
Type requirements
-T must meet the requirements of DefaultInsertable in order to use overload (1).
-T must meet the requirements of CopyInsertable in order to use overload (2).
Return value
(none)
Complexity
Linear in the difference between the current size and count. Additional complexity possible due to list traversal to reach the first element to erase/the end position to insert
Modifiers
swap( )
swaps the contents Parameters other - container to exchange the contents with Return value (none)
Exceptions
(none)
(until C++17) noexcept specification: noexcept(std::allocator_traits::is_always_equal::value) (since C++17) Complexity Constant.