1. 《STL源码解析》P72的uninitialized_fill_n函数;
#include <iostream>
#include <new.h>
//using namespace std; //不要std,因为std命名空间中也有input_iterator_tag等的定义
struct input_iterator_tag //std命名空间中也有input_iterator_tag的定义
{
};
struct output_iterator_tag
{
};
struct forward_iterator_tag:public input_iterator_tag
{
};
struct bidirectional_iterator_tag:public forward_iterator_tag
{
};
struct random_access_iterator_tag:public bidirectional_iterator_tag
{
};
struct __true_type{};
struct __false_type{};
template <class T1, class T2>
inline void construct( T1 *p, const T2& value )
{
new (p) T1(value);
return;
}
template <class OutputIterator, class Size, class T>
OutputIterator fill_n( OutputIterator first, Size n, const T& value )
{
for( ; n > 0; --n, ++first )
{
*first = value;
}
return first;
}
template <class Category, class