首页 > 代码库 > STL源码分析一:组态

STL源码分析一:组态

#include <iostream>

using namespace std;

template <typename T>
class testClass{
	public:
		static int _data;
};

int testClass<int>::_data = http://www.mamicode.com/1;>


#include <iostream>

using namespace std;

template <class I, class O>
struct testClass
{
	testClass(){cout << "I, O" << endl;}
};

template <class T>
struct testClass<T*, T*>
{
	testClass(){cout << "T*, T*" << endl;}
};

template <class T>
struct testClass<const T*, T*>
{
	testClass(){cout << "const T*, T*" << endl;}
};

int main()
{
	testClass<int ,char> obj1;
	testClass<int *, int *> obj2;
	testClass<const int*, int*> obj3;
	return 0;
}
 

#include <iostream>

using namespace std;

class alloc{

};

template <class T, class Alloc = alloc>
class vector {
public :
	void swap(vector<T, Alloc>&) { cout << "swap()" << endl;}
};

#ifdef _STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class T, class Alloc>
inline void swap(vector<T, Alloc>& x, vector<T, Alloc>& y)
{
	x.swap(y);
}
#endif

int main()
{
	vector<int> x, y;
	swap(x, y);
	return 0;
}

#include <iostream>

using namespace std;

class alloc {

};

template <class T, class Alloc = alloc>
class vector{
public :
	typedef T value_type;
	typedef value_type* iterator;

	template <class I>
		void insert(iterator position, I first, I last){
			cout << "insert()" << endl;
		}
};

int main()
{
	int ia[5]={0,1,2,3,4};

	vector<int> x;
	vector<int>::iterator ite;
	x.insert(ite, ia, ia+5);
	return 0;
}

#include <iostream>
#include <cstddef>

using namespace std;

class alloc{

};

template <class T, class Alloc = alloc, size_t BufSiz = 0>
class deque {
public :
	deque() { cout << "deque" << endl; }
};

template <class T, class Sequence = deque<T> >
class stack {
public :
	stack() { cout << "stack" << endl; }
private:
	Sequence c;
};

int main()
{
	stack<int> x;
	return 0;
}


STL源码分析一:组态