pt 자료입니다.
아래는 소스
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
#include <iostream>
#include <string.h>
#include <boost/version.hpp>
#include <random>
#include <windows.h>
using namespace std;
using namespace std::tr1;
//---------------------------------------------------------------------------
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
int maj = BOOST_VERSION /10000;
int min = BOOST_VERSION /100%1000;
std::cout << maj << "\r\n";
std::cout << min << "\r\n";
std::cout << "boost version - " << BOOST_VERSION <<"\r\n";
mt19937 Generator; //난수엔진 - 당연히 에러가 난다. 구조상 0으로 나누게 된다.
//ranlux3 Generator;
uniform_int<> dst(100, 500); //범위지정자
Generator.seed(GetTickCount()); //seed 초기화
variate_generator<mt19937, uniform_int<> > rand(Generator, dst); //난수생성기
//variate_generator<ranlux3, uniform_int<> > rand(Generator, dst); //난수생성기
for( int i = 1;i < 1000; ++i )
{
cout << rand() << endl; //난수생성기는 () 연산자를 난수생성 연산자로 오버로딩 해 놓았습니다.
}
std::cin >> min ;
return 0;
}
//---------------------------------------------------------------------------
각종 예제
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
#include <iostream>
#include <boost/tuple/tuple.hpp>
#include <memory>
using namespace std;
using namespace boost;
#include <boost/array.hpp>
//---------------------------------------------------------------------------
tuple<int, int, int> foo()
{
tuple<int, int, int> ret(100, 200, 300);
return ret;
}
void Release( int* p )
{
cout << "release" << endl;
free(p);
}
struct deleter
{
void operator()(int *p)
{
delete p;
}
};
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
// C의배열
int b[3] = { 1, 2, 3 };
// array
array<int, 3> c = { 1, 2, 3 };
cout << ">>> array 출력 " << endl;
cout << c[0] << endl;
cout << c[2] << endl;
cout << ">>> begin, end의 STL 기본 문법으로 배열과의 차이를 보자" << endl;
array<int, 4> c0 = {0, 1, 2, 3 };
array<int,4>::const_iterator it;
for (it = c0.begin(); it != c0.end(); ++it)
std::cout << " " << *it;
std::cout << std::endl;
cout << ">>> MAX size : ";
std::cout << " " << c0.max_size();
std::cout << std::endl;
//------------------------------------------------------------------------------
// tuple code - testcode
//------------------------------------------------------------------------------
tuple<int, int, int> r = foo();
cout << "tuple은 n 개의 값을 가지고 올 때 편하다." << endl;
cout << "tuple은 게임에서 유저 착용 아이템 정보를 가져올 때 편하다." << endl;
cout << "tuple은 10개까지 가져올 수 있지만 컴파일러마다 다르다 ㅠㅠ" << endl;
cout << get<0>(r) << endl;
cout << get<1>(r) << endl;
cout << get<2>(r) << endl;
tuple<int> one;
tuple<int, int> two(1, 2);
tuple<int, int, int, int, int> five;
cout << "<<< 튜플 사이즈 출력 "<< endl;
cout << sizeof(five) << endl;
cout << sizeof(two) << endl;
//------------------------------------------------------------------------------
cout << ">>> shared pointer" << endl;
shared_ptr<int> sp0;
cout << "(bool)sp0 == " << std::boolalpha << (bool)sp0 << std::endl;
shared_ptr<int> sp1(new int(100));
cout << "*sp1 == " << *sp1 << endl;
shared_ptr<int> sp2(new int(200), deleter());
cout << "*sp2 == " << *sp2 << endl;
shared_ptr<int> sp3(sp2);
cout << "*sp3 == " << *sp3 << endl;
weak_ptr<int> wp(sp3);
shared_ptr<int> sp4(wp);
cout << "*sp4 == " << *sp4 << endl;
auto_ptr<int> ap(new int(500));
shared_ptr<int> sp5(ap);
cout << "*sp5 == " << *sp5 << endl;
cout << "자원 관리는 shared pointer에게~" << endl;
cout << "Multi thread에서도 원본 무결성 유지~ " << endl;
cout << "공용 라이브러리, 공용 데이터로 사용이 편리~ " << endl;
int i;
cin >> i;
return 0;
}
//---------------------------------------------------------------------------
|