-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator_traits.hpp
50 lines (40 loc) · 1.6 KB
/
iterator_traits.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef _ASP_ITERATOR_TRAITS_HPP_
#define _ASP_ITERATOR_TRAITS_HPP_
#include "basic_param.hpp"
namespace asp {
struct fixed_iterator {}; // support * ->
struct forward_iterator_tag : public fixed_iterator {}; // support +
struct backward_iterator_tag : public fixed_iterator {}; // support -
struct bidirectional_iterator_tag : public forward_iterator_tag, public backward_iterator_tag {}; // support + and -
struct random_access_iterator_tag : public bidirectional_iterator_tag {}; // support self- and +n
template <typename _Iter> class iterator_traits;
template <typename _Iter> class iterator_traits {
public:
typedef typename _Iter::iterator_category iterator_category;
typedef typename _Iter::value_type value_type;
typedef typename _Iter::pointer pointer;
typedef typename _Iter::reference reference;
typedef typename _Iter::difference_type difference_type;
};
template <typename _Tp> class iterator_traits <_Tp*> {
public:
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef _Tp* pointer;
typedef _Tp& reference;
typedef asp::difference_type difference_type;
};
template <typename _Tp> class iterator_traits <const _Tp*> {
public:
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef const _Tp* pointer;
typedef const _Tp& reference;
typedef asp::difference_type difference_type;
};
template <typename _Iter> auto _A_iterator_category(const _Iter&)
-> typename asp::iterator_traits<_Iter>::iterator_category {
return typename asp::iterator_traits<_Iter>::iterator_category();
};
};
#endif