/*
prepare.cpp
演示了阅读 STL 原代码的一些预备知识
1. 模版以及模版的偏特化,是 STL 源代码里面用的很多的技术,
有效的解决了支持不同参数个和类型的问题;
2. 各式各样的宏定义,用于定义构造函数,重载函数实现,需要不断的展开,
这个也是平时代码很少见的特征
*/
//标明是使用 MS版本,本处使用 VS2012 update 4
#include "stdafx.h"
#include
#include
using namespace std;
#define join_1(a,b) a+b
#define join_2(a,b) ab
#define join_3(a,b) a##b
#define join_4(a,b) v_ ## a ## _ ## b ## _t
void test_micro()
{
//演示了宏的一些定义
int x = 11,y = 22;
std::cout<
int ab = 333;
std::cout<
std::cout<
std::cout<
std::cout<
//声明一个模版类,容许最少有一个模板参数,最多有4个模板参数,
//该最多模版参数的空模版没有实现,所以其他的就只能最多有3个模版参数了
//最后一个class = Null_class,无参数名称,是标明是不命名模板参数,
//Null_class 是一个空结构体,定义是: struct Null_class{};
//STL 原代码里面定义了一个 _Nil
struct Null_class{};
template
//专门化(偏特化)模版类
template
{
private:
_Fun m_v;
public:
_Bind_A(_Fun v):m_v(v)
{
//
}
const std::string cat()
{
std::stringstream str;
str<
}
};
template
{
private:
_Fun m_v;
public:
_Bind_A(_Fun v):m_v(v)
{
//
}
const std::string cat(v0_t &v)
{
std::stringstream str;
str<
}
};
//专门化(偏特化)模版类,同时演示了模板继存的方式
template
: public std::binary_function
{
private:
_Fun m_v;
public:
_Bind_A(_Fun v):m_v(v)
{
//
}
const std::string cat(v0_t &v,v1_t vv)
{
std::stringstream str;
str<
}
};
void test_template() _Bind_A _Bind_A int _tmain(int argc, _TCHAR* argv[]) std::cout<<"test_micro start\n"; system("pause"); return 0; test_micro start test_template start
{
_Bind_A
std::cout<
std::string s = "aa";
std::cout<
std::cout<
{
test_micro();
std::cout<<"test_micro end\n";
std::cout<<"\ntest_template start\n";
test_template();
std::cout<<"test_template end\n";
}
33
333
999
9999
99999
test_micro end
10
Caa
caa99.99
test_template end
请按任意键继续. . .