-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIterator.hpp
More file actions
79 lines (62 loc) · 2.52 KB
/
Iterator.hpp
File metadata and controls
79 lines (62 loc) · 2.52 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef ITERATOR_HPP
# define ITERATOR_HPP
# include <iostream>
# include <cstddef>
# include "ft_containers.hpp"
NAME_SPACE_START
// =============================================================================
// DEFINES THE CATEGORY OF AN ITERATOR: each tag is an empty type ==============
// input_iterator_tag corresponds to LegacyInputIterator.
struct input_iterator_tag { };
// output_iterator_tag corresponds to LegacyOutputIterator.
struct output_iterator_tag { };
// forward_iterator_tag corresponds to LegacyForwardIterator.
struct forward_iterator_tag : public input_iterator_tag { };
// bidirectional_iterator_tag corresponds to LegacyBidirectionalIterator.
struct bidirectional_iterator_tag : public forward_iterator_tag { };
// random_access_iterator_tag corresponds to LegacyRandomAccessIterator.
struct random_access_iterator_tag : public bidirectional_iterator_tag { };
// =============================================================================
// ITERATOR BASE CLASS =========================================================
template <class Category, class T, class Distance = std::ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator
{
typedef T value_type;
typedef Distance difference_type;
typedef Pointer pointer;
typedef Reference reference;
typedef Category iterator_category;
};
// =============================================================================
// ITERATOR TRAITS =============================================================
/* std::iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIterator types. This makes it possible to implement algorithms only in terms of iterators. */
template< class Iterator >
struct iterator_traits
{
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::value_type value_type;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference;
typedef typename Iterator::iterator_category iterator_category;
};
template< class T >
struct iterator_traits<T*>
{
typedef std::ptrdiff_t difference_type;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef random_access_iterator_tag iterator_category;
};
template< class T >
struct iterator_traits<const T*>
{
typedef std::ptrdiff_t difference_type;
typedef T value_type;
typedef const T* pointer;
typedef const T& reference;
typedef random_access_iterator_tag iterator_category;
};
NAME_SPACE_END
#endif