Boost 1.55 버전 기준으로 작성했습니다.


#include <iostream>

#include <algorithm>

#include <wtypes.h>

#include <string>

#include <vector>

#include <map>

#include <stack>

#include <set>

#include <queue>


#include <boost/array.hpp>


// 벡터에 boost::assign 을 사용한다.

// 더이상 자세한 설명은 생략한다.

#include <boost/assign.hpp>


#include <boost/tuple/tuple.hpp>

#include <boost/tuple/tuple_io.hpp>

#include <boost/foreach.hpp>


using namespace std;

using namespace boost;

using namespace boost::assign;


//

// stl container 초기화 또는 값을 대입하였을 경우

// 아주 아주 편리하게 도와주는 녀석


void Assign_Test()

{


vector< int > v = list_of(1)(2)(3)(4).to_container( v );

list< int > l = list_of(1)(2)(3)(4).to_container( l );

set< int > s = list_of(1)(2)(3)(4).to_container( s );

map< int,int > m = map_list_of(1,2)(2,3)(3,4)(4,5).to_container( m );


stack< int > st = list_of(1)(2)(3)(4).to_adapter( st );

queue< int > q = list_of(1)(2)(3)(4).to_adapter( q );


array< int, 4 > a = list_of(1)(2)(3)(4).to_array( a );


// v 출력

BOOST_FOREACH( int& iter, v )

{

std::cout << "벡터 값 : " << iter << std::endl;

}


// v 출력

BOOST_FOREACH( int& iter, l )

{

std::cout << "리스트 값 : " << iter << std::endl;

}


// v 출력

BOOST_FOREACH( int& iter, s )

{

std::cout << "Set 값 : " << iter << std::endl;

}


int key;

int value;

BOOST_FOREACH( boost::tie( key, value ), m )

{

std::cout << "Key : " << key << "Value : " << value << std::endl;

}


// v 출력

/*BOOST_FOREACH( int& iter, st )

{

std::cout << "Stack 값 : " << iter << std::endl;

}


// v 출력

BOOST_FOREACH( int& iter, q )

{

std::cout << "Queue 값 : " << iter << std::endl;

}*/


// v 출력

BOOST_FOREACH( int& iter, a )

{

std::cout << "Array 값 : " << iter << std::endl;

}

}

'Boost' 카테고리의 다른 글

Boost Foreach 샘플  (0) 2016.01.29
Boost Bind 샘플  (0) 2016.01.29
Boost Array 샘플  (0) 2016.01.29
Boost Any 샘플  (0) 2016.01.29
boost::mpl 라이브러리를 이용한 Packet의 자동 생성 및 처리 방법  (0) 2014.05.26
      Boost  |  2016. 1. 29. 16:54



홍쿤사마's Blog is powered by Daum