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

Replaces the contents of the container.

# Declarations

void assign( size_type count, const T& value );
template< class InputIt >
void assign( InputIt first, InputIt last );
void assign( std::initializer_list<T> ilist );

(since C++11)

# Parameters

# Example

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

# Defect reports

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

# See also