map::map
지도를 비어 있거나 해당 복사본의 모든 또는 일부 다른 맵의 일부를 만듭니다.
map( );
explicit map(
const Traits& _Comp
);
map(
const Traits& _Comp,
const Allocator& _Al
);
map(
const map& _Right
);
template<class InputIterator>
map(
InputIterator _First,
InputIterator _Last
);
template<class InputIterator>
map(
InputIterator _First,
InputIterator _Last,
const Traits& _Comp
);
template<class InputIterator>
map(
InputIterator _First,
InputIterator _Last,
const Traits& _Comp,
const Allocator& _Al
);
map(
map&& _Right
);
매개 변수
Parameter |
설명 |
_Al |
기본이 맵 개체에 사용할 저장소 할당자 클래스 할당자. |
_Comp |
비교 함수 형식의 const특성 기본 구조에서 요소를 주문 하는 데 사용 hash_compare. |
_Right |
지도 중 복사본으로 구성 된 집합입니다. |
_First |
복사할 요소의 범위에 있는 첫 번째 요소의 위치입니다. |
_Last |
복사할 요소의 범위를 벗어나는 첫 번째 요소의 위치입니다. |
설명
모든 생성자는 맵의 메모리 저장소를 관리 하 고 나중에 반환할 호출 하 여 할당자 객체 유형을 저장할 get_allocator.할당자 매개 변수 클래스 선언과 전처리 매크로 대체 할당자를 대체 하는 데 종종 생략 합니다.
해당 맵 모든 생성자를 초기화합니다.
모든 생성자 함수 개체 형식의 키 맵 간에 순서를 설정할 수 사용 되 고 나중에 반환할 호출 하 여 특성을 저장 key_comp.
빈 초기 맵, 두 번째는 처음 세 명의 생성자를 지정 비교 함수의 형식을 지정 (_Comp) 입력 요소와 세 번째 순서를 설정 하는 데 사용할 할당자를 명시적으로 지정 (_Al) 데.말 명시적 자동 형식 변환을 특정 종류를 표시 하지 않습니다.
네 번째 생성자는 맵의 복사본 지정 _Right.
범위는 다음 세 명의 생성자 복사 [_First, _Last)에서 비교 함수를 클래스의 형식을 지정 하는 명시적인 증가 맵의 성분 및 할당자.
이동 하 여 지도의 복사본 마지막 생성자 지정 _Right.
예제
// map_map.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
typedef pair <int, int> Int_Pair;
map <int, int>::iterator m1_Iter, m3_Iter, m4_Iter, m5_Iter, m6_Iter, m7_Iter;
map <int, int, greater<int> >::iterator m2_Iter;
// Create an empty map m0 of key type integer
map <int, int> m0;
// Create an empty map m1 with the key comparison
// function of less than, then insert 4 elements
map <int, int, less<int> > m1;
m1.insert( Int_Pair( 1, 10 ) );
m1.insert( Int_Pair( 2, 20 ) );
m1.insert( Int_Pair( 3, 30 ) );
m1.insert( Int_Pair( 4, 40 ) );
// Create an empty map m2 with the key comparison
// function of geater than, then insert 2 elements
map <int, int, greater<int> > m2;
m2.insert( Int_Pair( 1, 10 ) );
m2.insert( Int_Pair( 2, 20 ) );
// Create a map m3 with the
// allocator of map m1
map <int, int>::allocator_type m1_Alloc;
m1_Alloc = m1.get_allocator( );
map <int, int> m3( less<int>( ), m1_Alloc );
m3.insert( Int_Pair( 3, 30 ) );
// Create a copy, map m4, of map m1
map <int, int> m4( m1 );
// Create a map m5 by copying the range m1[_First, _Last)
map <int, int>::const_iterator m1_bcIter, m1_ecIter;
m1_bcIter = m1.begin( );
m1_ecIter = m1.begin( );
m1_ecIter++;
m1_ecIter++;
map <int, int> m5(m1_bcIter, m1_ecIter);
// Create a map m6 by copying the range m4[_First, _Last)
// and with the allocator of map m2
map <int, int>::allocator_type m2_Alloc;
m2_Alloc = m2.get_allocator( );
map <int, int> m6( m4.begin( ), ++m4.begin( ), less<int>( ), m2_Alloc);
cout << "m1 =";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter -> second;
cout << endl;
cout << "m2 =";
for ( m2_Iter = m2.begin( ); m2_Iter != m2.end( ); m2_Iter++ )
cout << " " << m2_Iter -> second;
cout << endl;
cout << "m3 =";
for ( m3_Iter = m3.begin( ); m3_Iter != m3.end( ); m3_Iter++ )
cout << " " << m3_Iter -> second;
cout << endl;
cout << "m4 =";
for ( m4_Iter = m4.begin( ); m4_Iter != m4.end( ); m4_Iter++ )
cout << " " << m4_Iter -> second;
cout << endl;
cout << "m5 =";
for ( m5_Iter = m5.begin( ); m5_Iter != m5.end( ); m5_Iter++ )
cout << " " << m5_Iter -> second;
cout << endl;
cout << "m6 =";
for ( m6_Iter = m6.begin( ); m6_Iter != m6.end( ); m6_Iter++ )
cout << " " << m6_Iter -> second;
cout << endl;
// Create a map m7 by moving m5
cout << "m7 =";
map<int, int> m7(move(m5));
for ( m7_Iter = m7.begin( ); m7_Iter != m7.end( ); m7_Iter++ )
cout << " " << m7_Iter -> second;
cout << endl;
}
Output
m1 = 10 20 30 40
m2 = 20 10
m3 = 30
m4 = 10 20 30 40
m5 = 10 20
m6 = 10
m7 = 10 20
요구 사항
헤더: <map>
네임 스페이스: std