std::forward_list<T,Allocator>::resize (3) - Linux Manuals
std::forward_list<T,Allocator>::resize: std::forward_list<T,Allocator>::resize
Command to display std::forward_list<T,Allocator>::resize
manual in Linux: $ man 3 std::forward_list<T,Allocator>::resize
NAME
std::forward_list<T,Allocator>::resize - std::forward_list<T,Allocator>::resize
Synopsis
void resize( size_type count ); (1)
void resize( size_type count, const value_type& value ); (2)
Resizes the container to contain count elements.
If the current size is greater than count, the container is reduced to its first count elements.
If the current size is less than count,
1) additional default-inserted elements are appended
2) additional copies of value are appended
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
Example
// Run this code
#include <iostream>
#include <forward_list>
int main()
{
std::forward_list<int> c = {1, 2, 3};
std::cout << "The forward_list holds: ";
for(auto& el: c) std::cout << el << ' ';
std::cout << '\n';
c.resize(5);
std::cout << "After resize up to 5: ";
for(auto& el: c) std::cout << el << ' ';
std::cout << '\n';
c.resize(2);
std::cout << "After resize down to 2: ";
for(auto& el: c) std::cout << el << ' ';
std::cout << '\n';
}
Output:
The forward_list holds: 1 2 3
After resize up to 5: 1 2 3 0 0
After resize down to 2: 1 2
See also
inserts elements after an element
insert_after (public member function)
erases an element after an element
erase_after (public member function)
Pages related to std::forward_list<T,Allocator>::resize
- std::forward_list<T,Allocator>::remove,remove_if (3) - std::forward_list<T,Allocator>::remove,remove_if
- std::forward_list<T,Allocator>::reverse (3) - std::forward_list<T,Allocator>::reverse
- std::forward_list<T,Allocator>::assign (3) - std::forward_list<T,Allocator>::assign
- std::forward_list<T,Allocator>::before_begin,cbefore_begin (3) - std::forward_list<T,Allocator>::before_begin,cbefore_begin
- std::forward_list<T,Allocator>::begin,std::forward_list<T,Allocator>::cbegin (3) - std::forward_list<T,Allocator>::begin,std::forward_list<T,Allocator>::cbegin
- std::forward_list<T,Allocator>::clear (3) - std::forward_list<T,Allocator>::clear
- std::forward_list<T,Allocator>::emplace_after (3) - std::forward_list<T,Allocator>::emplace_after
- std::forward_list<T,Allocator>::emplace_front (3) - std::forward_list<T,Allocator>::emplace_front
- std::forward_list<T,Allocator>::empty (3) - std::forward_list<T,Allocator>::empty
- std::forward_list<T,Allocator>::end,std::forward_list<T,Allocator>::cend (3) - std::forward_list<T,Allocator>::end,std::forward_list<T,Allocator>::cend
- std::forward_list<T,Allocator>::erase_after (3) - std::forward_list<T,Allocator>::erase_after
- std::forward_list<T,Allocator>::forward_list (3) - std::forward_list<T,Allocator>::forward_list
- std::forward_list<T,Allocator>::front (3) - std::forward_list<T,Allocator>::front
- std::forward_list<T,Allocator>::get_allocator (3) - std::forward_list<T,Allocator>::get_allocator
- std::forward_list<T,Allocator>::insert_after (3) - std::forward_list<T,Allocator>::insert_after
- std::forward_list<T,Allocator>::max_size (3) - std::forward_list<T,Allocator>::max_size
- std::forward_list<T,Allocator>::merge (3) - std::forward_list<T,Allocator>::merge
- std::forward_list<T,Allocator>::operator= (3) - std::forward_list<T,Allocator>::operator=
- std::forward_list<T,Allocator>::pop_front (3) - std::forward_list<T,Allocator>::pop_front
- std::forward_list<T,Allocator>::push_front (3) - std::forward_list<T,Allocator>::push_front
- std::forward_list<T,Allocator>::sort (3) - std::forward_list<T,Allocator>::sort
- std::forward_list<T,Allocator>::splice_after (3) - std::forward_list<T,Allocator>::splice_after
- std::forward_list<T,Allocator>::swap (3) - std::forward_list<T,Allocator>::swap
- std::forward_list<T,Allocator>::unique (3) - std::forward_list<T,Allocator>::unique
- std::forward_list<T,Allocator>::~forward_list (3) - std::forward_list<T,Allocator>::~forward_list
- std::forward_list (3) - std::forward_list