std::deque<T,Allocator>::assign
Min standard notice:
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
count: the new size of the containervalue: the value to initialize elements of the container withfirst, last: the range to copy the elements fromilist: std::initializer_list to copy the values from
# 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
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2209 | C++98 | the replacement operation was required to be implemented aserasing all existing elements followed by inserting the given elements | removed therequirement |