1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream> 
#include <map> 
#include <vector> 
 
using namespace std; 
 
int main() 
    map<intint>    mapTest; 
    mapTest.insert( pair< int,int >( 1,0 ) ); 
    mapTest.insert( pair< int,int >( 2,0 ) ); 
    mapTest.insert( pair< int,int >( 3,0 ) ); 
    mapTest.insert( pair< int,int >( 4,0 ) ); 
    mapTest.insert( pair< int,int >( 5,0 ) ); 
 
    vector<map<intint>> vmVectorTest; 
    vmVectorTest.push_back(mapTest); 
 
    vector<map<intint>>::iterator vitr; 
    vitr = vmVectorTest.begin(); 
 
    map<intint>::iterator mapitr; 
    mapitr = vitr->begin(); 
 
    do 
    { 
        cout << mapitr->first << " , " << mapitr->second << endl; 
 
        ++mapitr; 
    }while(mapitr != vitr->end()); 
 
    return 0; 
}

vector에 map을 담을 생각을 한 이유는 자유롭게 변형되는 맵 배열을 생각하게 되었다.

현재로써는 사용량이 빈번하지 않을 것으로 예상되지만 유용하게 사용할 일이 있을거란 생각에 테스트 코드를 작성하게 되었다.

 

위의 코드를 보면 vector에 map을 담았지만 다른 각도로 보면 다양한 STL 컨네이너들이 각자 상황에 맞게 포함 될 수 있음을

의미한다. 이 의미는 자유롭게 사용하여 필요할 때 꺼내 사용하면 된다.

 

퍼포먼스를 먼저 생각하는 분이라면 하나의 연산이라도 하지 않아야 한다는 가정이 붙겠지만 일단 요즘 시대의 컴퓨터는

이 정도의 내용을 허용하므로 자유롭게 사용하는게 더 이익일 수있다는 사실을 생각하면 좋다.

 

고정형의 배열을 사용하거나 매번 new를 이용한 배열 생성의 형태라면 vector가 더 효과적이므로 한번 정도 생각을 해볼 수 있는

문장이다.


+ Recent posts