Namespaces
Variants

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

출처: ko.cppreference.net

 
 
 
 
void assign( size_type count, const T& value );
(1) (C++26부터)
template< class InputIt >
void assign( InputIt first, InputIt last );
(2) (C++26부터)
void assign( std::initializer_list<T> ilist );
(3) (C++11부터)

컨테이너의 내용을 대체합니다.

1) 내용을 count 값 value의 복사본으로 대체합니다.
2) 내용을 범위 [first, last)에 있는 것들의 복사본으로 대체합니다.
인수 중 하나가 *this에 대한 반복자인 경우 동작이 정의되지 않습니다. 이 오버로드는 InputIt이 LegacyInputIterator를 만족하는 경우에만 오버로드 해결에 참여합니다.
3) 내용을 ilist의 요소들로 대체합니다.


매개변수

count - 컨테이너의 새 크기
value - 컨테이너의 요소를 초기화할 값
first, last - 복사할 요소의 소스 범위를 정의하는 반복자 쌍
ilist - std::initializer_list 값을 복사해올

복잡도

1) count에 선형.
2) first과 last 사이의 거리에 선형.
3) ilist.size()에 선형.

예제

다음 코드는 assign를 사용하여 std::hive<char>에 여러 문자를 추가합니다:

#include <hive>
#include <iostream>
#include <string>

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

출력:

a a a a a
b b b b b b
C + + 2 6

참고 항목

컨테이너에 값의 범위를 할당합니다
(공개 멤버 함수)
컨테이너에 값을 할당합니다
(공개 멤버 함수)