Namespaces
Variants

std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>:: replace

From cppreference.net

void replace ( key_container_type && key_cont, mapped_container_type && mapped_cont ) ;
(C++23 이후)

기반 컨테이너 c 를 교체합니다. 다음 코드와 동일합니다:

c.keys = std::move(key_cont);
c.values = std::move(mapped_cont);

다음 조건이 충족되어야 합니다:

  • 다음 표현식 key_cont. size ( ) == mapped_cont. size ( ) true 여야 합니다.
  • key_cont 의 요소들은 compare 에 따라 정렬되어야 합니다.

    그렇지 않으면 동작은 정의되지 않습니다.

목차

매개변수

keys_cont - 정렬된 키 컨테이너로 KeyContainer 타입이며, 그 내용이 * this 로 이동됩니다
mapped_cont - 매핑된 값들의 컨테이너로 MappedContainer 타입이며, 그 내용이 * this 로 이동됩니다

반환값

(없음)

복잡도

적응된 컨테이너들에 적용된 std::move 의 복잡도와 동일합니다.

예제

#include <algorithm>
#include <cassert>
#include <flat_map>
#include <print>
#include <vector>
int main()
{
    std::vector<int> keys{1, 2, 3};
    assert(std::ranges::is_sorted(keys));
    std::vector<double> values{2.2, 3.3, 1.1};
    assert(keys.size() == values.size());
    std::flat_multimap<int, double> map;
    assert(map.empty());
    map.replace(keys, values);
    assert(map.size() == 3);
    assert(map.keys() == 3);
    assert(map.values() == 3);
    assert(keys.empty());
    assert(values.empty());
    std::println("{}", map);
}

출력:

{1: 2.2, 2: 3.3, 3: 1.1}

참고 항목

내부 컨테이너를 추출합니다
(public member function)