std::forward_list<T,Allocator>::assign

Replaces the contents of the container.

# Declarations

void assign( size_type count, const T& value );

(since C++11)

template< class InputIt >
void assign( InputIt first, InputIt last );

(since C++11)

void assign( std::initializer_list<T> ilist );

(since C++11)

# Parameters

# Example

#include <forward_list>
#include <iostream>
#include <string>
 
int main()
{
    std::forward_list<char> characters;
 
    auto print_forward_list = [&]()
    {
        for (char c : characters)
            std::cout << c << ' ';
        std::cout << '\n';
    };
 
    characters.assign(5, 'a');
    print_forward_list();
 
    const std::string extra(6, 'b');
    characters.assign(extra.begin(), extra.end());
    print_forward_list();
 
    characters.assign({'C', '+', '+', '1', '1'});
    print_forward_list();
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2209C++11the replacement operation was required to be implemented aserasing all existing elements followed by inserting the given elementsremoved therequirement

# See also