std::forward_list::forward_list
From Cppreference
explicit forward_list( const Allocator& alloc = Allocator() );
|
(1) | (C++11 feature) |
forward_list( size_type count,
const T& value = T(), |
(2) | (C++11 feature) |
explicit forward_list( size_type count );
|
(3) | (C++11 feature) |
template <class InputIterator>
forward_list( InputIterator first, InputIterator last, |
(4) | (C++11 feature) |
forward_list( const forward_list& other );
|
(5) | (C++11 feature) |
forward_list( const forward_list& other, const Allocator& alloc );
|
(5) | (C++11 feature) |
forward_list( forward_list&& other )
|
(6) | (C++11 feature) |
forward_list( forward_list&& other, const Allocator& alloc );
|
(6) | (C++11 feature) |
forward_list( std::initializer_list<T> init,
const Allocator& alloc = Allocator() ); |
(7) | (C++11 feature) |
Constructs new container from a variety of data sources and optionally using user supplied allocator alloc.
1) default constructor. Constructs empty container.
2) constructs the container with count copies of elements with value value.
3) constructs the container with count copies of elements with value T().
4) constructs the container with the contents of the range [first, last).
5) copy constructor. Constructs the container with the copy of the contents of other.
6) move constructor. Constructs the container with the contents of other using move semantics.
7) constructs the container with the contents of the initializer list init.
Contents |
[edit] Parameters
alloc | - | allocator to use for all memory allocations of this container |
count | - | the size of the container |
value | - | the value to initialize elements of the container with |
first, last | - | the range to copy the elements from |
other | - | another container to be used as source to initialize the elements of the container with |
init | - | initializer list to initialize the elements of the container with |
[edit] Complexity
1) constant
2-3) linear in count
4) linear in distance between first and last
5) linear in size of other
6) constant. If alloc is given and alloc != other.get_allocator(), then linear.
7) linear in size of init
[edit] Example
#include <forward_list> #include <string> int main() { // c++0x initializer list syntax: std::forward_list<std::string> words1 {"the", "frogurt", "is", "also", "cursed"}; // words2 == words1 std::forward_list<std::string> words2(words1.begin(), words1.end()); // words3 == words1 std::forward_list<std::string> words3(words1); // words4 is {"Mo", "Mo", "Mo", "Mo", "Mo"} std::forward_list<std::string> words4(words1.size(), "Mo"); return 0; }
[edit] See also
|
assigns values to the container (public member function) |
|
|
assigns values to the container (public member function) |