1: /*
2: author:justinzhang
3: email:uestczhangchao@gmail.com
4: time:2012-8-23 10:28:53
5: desc: value_type , from <the annotated stl source>, chapter 3, p86
6: iterator_traits will be coflict with system, so i use another name.
7: */
8: #include<iostream>
9: using namespace std;
10:
11: template <class T>
12: struct MyIter
13: {
14: typedef T value_type;
15: T* ptr;
16: MyIter(T* p=0) : ptr(p){}
17: T& operator*() const {return *ptr;}
18:
19: };
20: template <class I>
21: struct iterator_traitss
22: {
23: typedef typename I::value_type value_type;
24: };
25:
26: template <class T>
27: struct iterator_traitss<T*>
28: {
29: typedef T value_type;
30: };
31:
32: template <class I>
33: typename iterator_traitss<I>::value_type
34: func(I ite)
35: {
36: return *ite;
37: }
38:
39: int main()
40: {
41: MyIter<int> ite(new int(8));
42: cout << func(ite)<<endl;
43: return 0;
44: }