码迷,mamicode.com
首页 > 其他好文 > 详细

stl源码为什么要大量使用typedef?

时间:2017-08-07 20:45:32      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:log   download   reference   ptr   .com   load   str   enc   href   

SGI源码download,《stl源码剖析》里展示了vector的部分源码:

 1 template <class T, class Alloc = alloc>
 2 class vector {
 3 public:
 4   typedef T value_type;
 5   typedef value_type* pointer;
 6   typedef const value_type* const_pointer;
 7   typedef value_type* iterator;
 8   typedef const value_type* const_iterator;
 9   typedef value_type& reference;
10   typedef const value_type& const_reference;
11   typedef size_t size_type;
12   typedef ptrdiff_t difference_type;
13   

stl里的string menber types 里含有的value_type等也是类型别名,迭代器也是。如果是用户自定义一个string, T,T*的写法明显比value_type、pointer更方便。

stl源码为什么要大量使用typedef?

标签:log   download   reference   ptr   .com   load   str   enc   href   

原文地址:http://www.cnblogs.com/hchacha/p/7300857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!