다음을 통해 공유


set::emplace

(복사 또는 이동 작업이 수행되지 않은)장소에 생성 된 요소를 삽입합니다.

template<class... Args>
    pair<iterator, bool> emplace(
        Args&&... args
);

매개 변수

Parameter

설명

args

구성 요소와 동일한 값을 갖는 순서가 포함 되어 있지 않으면, 인수는 집합에 삽입 될 요소를 구문으로 전달합니다.

반환 값

은 삽입이 만들어진 경우 true를 반환하고, 맵이 순서대로 동일한 값을 가진 요소를 이미 포함하고 있는 경우 false를 반환합니다. 반환 값 쌍의 반복기 구성 요소는 새 요소가 삽입된 부분의 주소 (true일 경우) 또는 요소가 이미 위치하고 있는 부분의 주소를 (false일 경우) 반환합니다.

설명

이 함수에 의해 참조가 없거나 반복기가 무효화 됩니다.

Emplacement하는 동안, 예외가 나타나면, 컨테이너의 상태는 수정되지 않습니다.

예제

// set_emplace.cpp
// compile with: /EHsc
#include <set>
#include <string>
#include <iostream>

using namespace std;

template <typename S> void print(const S& s) {
    cout << s.size() << " elements: ";

    for (const auto& p : s) {
        cout << "(" << p << ") ";
    }

    cout << endl;
}

int main()
{
    set<string> s1;

    auto ret = s1.emplace("ten");

    if (!ret.second){
        cout << "Emplace failed, element with value \"ten\" already exists."
            << endl << "  The existing element is (" << *ret.first << ")"
            << endl;
        cout << "set not modified" << endl;
    }
    else{
        cout << "set modified, now contains ";
        print(s1);
    }
    cout << endl;

    ret = s1.emplace("ten");

    if (!ret.second){
        cout << "Emplace failed, element with value \"ten\" already exists."
            << endl << "  The existing element is (" << *ret.first << ")"
            << endl;
    }
    else{
        cout << "set modified, now contains ";
        print(s1);
    }
    cout << endl;
}

Output

set modified, now contains 1 elements: (ten)

Emplace failed, element with value "ten" already exists.
  The existing element is (ten)

요구 사항

헤더: <설정>

네임스페이스: std

참고 항목

참조

<set>

set 클래스

표준 템플릿 라이브러리