-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiterator_traits.hpp
57 lines (48 loc) · 1.4 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
51
52
53
54
55
56
57
/*
* File: iterator_traits.hpp
* Project: ft_containers
* Created Date: 2023/01/28
* Author: nkim
* Copyright (c) 2022 nkim
*/
#ifndef ITERATOR_TRAITS_HPP_
#define ITERATOR_TRAITS_HPP_
#include <cstddef>
#include <iterator>
namespace ft {
/**
* @class iterator_traits
* @namespace ft
* @brief
* 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.
*
* @see https://en.cppreference.com/w/cpp/iterator_traits/iterator_traits
*/
template<typename Iter>
struct iterator_traits {
typedef typename Iter::difference_type difference_type;
typedef typename Iter::value_type value_type;
typedef typename Iter::pointer pointer;
typedef typename Iter::reference reference;
typedef typename Iter::iterator_category iterator_category;
};
template<typename Tp>
struct iterator_traits<Tp *> {
typedef std::ptrdiff_t difference_type;
typedef Tp value_type;
typedef Tp *pointer;
typedef Tp &reference;
typedef std::random_access_iterator_tag iterator_category;
};
template<typename Tp>
struct iterator_traits<const Tp *> {
typedef std::ptrdiff_t difference_type;
typedef Tp value_type;
typedef const Tp *pointer;
typedef const Tp &reference;
typedef std::random_access_iterator_tag iterator_category;
};
} // namespace ft
#endif //ITERATOR_TRAITS_HPP_