set::set
비어 있거나 모든 복사본이거나 또는 일부 다른 집합 부분인 집합을 생성합니다.
set( );
explicit set(
const Traits& Comp
);
set(
const Traits& Comp,
const Allocator& Al
);
set(
const set& Right
);
set(
set&& Right
);
set(
initializer_list<Type> IList
);
set(
initializer_list<Type> IList,
const Compare& Comp
);
set(
initializer_list<Type> IList,
const Compare& Comp,
const Allocator& Al
);
template<class InputIterator>
set(
InputIterator First,
InputIterator Last
);
template<class InputIterator>
set(
InputIterator First,
InputIterator Last,
const Traits& Comp
);
template<class InputIterator>
set(
InputIterator First,
InputIterator Last,
const Traits& Comp,
const Allocator& Al
);
매개 변수
Parameter |
설명 |
Al |
저장소 할당자 클래스는 Allocator에 설정된 집합 개체에 대해 사용됩니다. |
Comp |
const Traits 종류의 비교 함수는 Compare 기본적으로 하는 집합의 요소를 정렬하는데 사용됩니다. |
Rght |
생성된 집합은 사본이 되는 집합입니다. |
First |
복사할 요소의 범위에 있는 첫 번째 요소의 위치입니다. |
Last |
복사할 요소의 범위를 벗어나는 첫 번째 요소의 위치입니다. |
IList |
요소를 복사할 initializer_list. |
설명
모든 생성자는 집합에 대한 메모리 저장소를 관리하는 할당자 개체의 형식을 저장하고 get_allocator 호출함으로써 나중에 호출될 수 있습니다. 할당자 매개 변수는 클래스 선언과 대체 할당자를 대체하는데 사용되는 전처리 매크로에서 종종 생략됩니다.
모든 생성자의 집합 초기화합니다.
모든 생성자는 Traits형식의 함수 개체를 저장합니다. 그것은 집합의 키들 사이의 순서를 설정하는데 사용되고 key_comp를 호출함으로써 나중에 반환될 수 있습니다.
처음 세 개의 생성자는 빈 초기 집합을 지정하고, 두 번째는 요소들의 순서를 설정하는데 사용되는 비교 함수 (comp) 형식을 지정하고 세번째는 명시적으로 할당자 형식 (al)를 사용하기 위해 지정합니다. 키워드 explicit 는 자동 형식 변환의 특정 종류를 표시하지 않습니다.
네 번째 생성자는 right 집합의 사본을 지정합니다.
다음 세 명의 생성자의 요소를 지정 하는 initializer_list를 사용합니다.
다음 세 가지 생성자들은 집합의 범위 [first, last) 를 Traits 와 Allocator의 형식을 지정할 때 증가하는 명시성과 함께 복제합니다.
여덟 번째 생성자는 right 를 이동하여 집합의 복사본을 지정합니다.
예제
// set_set.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main()
{
using namespace std;
// Create an empty set s0 of key type integer
set <int> s0;
// Create an empty set s1 with the key comparison
// function of less than, then insert 4 elements
set <int, less<int> > s1;
s1.insert(10);
s1.insert(20);
s1.insert(30);
s1.insert(40);
// Create an empty set s2 with the key comparison
// function of less than, then insert 2 elements
set <int, less<int> > s2;
s2.insert(10);
s2.insert(20);
// Create a set s3 with the
// allocator of set s1
set <int>::allocator_type s1_Alloc;
s1_Alloc = s1.get_allocator();
set <int> s3(less<int>(), s1_Alloc);
s3.insert(30);
// Create a copy, set s4, of set s1
set <int> s4(s1);
// Create a set s5 by copying the range s1[_First, _Last)
set <int>::const_iterator s1_bcIter, s1_ecIter;
s1_bcIter = s1.begin();
s1_ecIter = s1.begin();
s1_ecIter++;
s1_ecIter++;
set <int> s5(s1_bcIter, s1_ecIter);
// Create a set s6 by copying the range s4[_First, _Last)
// and with the allocator of set s2
set <int>::allocator_type s2_Alloc;
s2_Alloc = s2.get_allocator();
set <int> s6(s4.begin(), ++s4.begin(), less<int>(), s2_Alloc);
cout << "s1 =";
for (auto i : s1)
cout << " " << i;
cout << endl;
cout << "s2 = " << *s2.begin() << " " << *++s2.begin() << endl;
cout << "s3 =";
for (auto i : s3)
cout << " " << i;
cout << endl;
cout << "s4 =";
for (auto i : s4)
cout << " " << i;
cout << endl;
cout << "s5 =";
for (auto i : s5)
cout << " " << i;
cout << endl;
cout << "s6 =";
for (auto i : s6)
cout << " " << i;
cout << endl;
// Create a set by moving s5
set<int> s7(move(s5));
cout << "s7 =";
for (auto i : s7)
cout << " " << i;
cout << endl;
// Create a set with an initializer_list
cout << "s8 =";
set<int> s8{ { 1, 2, 3, 4 } };
for (auto i : s8)
cout << " " << i;
cout << endl;
cout << "s9 =";
set<int> s9{ { 5, 6, 7, 8 }, less<int>() };
for (auto i : s9)
cout << " " << i;
cout << endl;
cout << "s10 =";
set<int> s10{ { 10, 20, 30, 40 }, less<int>(), s9.get_allocator() };
for (auto i : s10)
cout << " " << i;
cout << endl;
}
요구 사항
헤더: <설정>
네임스페이스: std