STL源码解析-03迭代器

************************************************
 * iterator_traits:这个与之前说的__type_traits的作用一样,只不过是专门针对iterator的。
 *
 * template <class T>
 * struct iterator_traits{
 *  typedef typename T::iterator_category iterator_category;
 *  typedef typename T::value_type value_type;//迭代器所指向的类型
 *  typedef typename T::difference_type defference_type;//两个迭代器之间的距离
 *  typedef typename T::pointer;//指针类型,指向迭代器所指向的类型
 *  typedef typename T::reference reference;//指向迭代器所指向的类型的引用类型
 * }
 *
 * 关于iterator_category的说明
 * category主要表示迭代器的类型,在STL中有五种迭代器,Input Iterator,Output Interator, Forward Iterator, Bidirectional Iterator和
 * Random Access Iterator。
 * 为了能够根据不同的类型,实现具体的偏序模板(因为有的只能加,有的只能读,所以需要根据具体类型实现,以提高效率),定义了与这五种相对应的categoty类。
 * struct input_iterator_tag {};
 * struct output_iterator_tag {};
 * struct forward_iterator_tag {};
 * struct bidirectional_iterator_tag {};
 * struct random_access_iterator_tag {};
 *
 * 为了便于得到iterator的以上类型说明,STL分别提供了value_type,distance_type等模板函数。
 * 所以在定义一个iterator的时候,需要在类中定义以上五种typedef。
 * ********************************************************
posted @ 2011-12-02 15:00  magicdog  阅读(192)  评论(0)    收藏  举报