-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninitlized.hpp
127 lines (110 loc) · 3.55 KB
/
uninitlized.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#include "myIterator.hpp"
#include "myTrait.hpp"
#include "myConstruct.hpp"
#include <string.h>
namespace MySTL
{
template <class InputIterator, class ForwordIterator>
inline ForwordIterator __uninitlize_copy_aux(InputIterator first,
InputIterator end, ForwordIterator result, __true_type) {
while (first != end) {
*result = *first;
++first;
++result;
}
return result;
}
template <class InputIterator, class ForwordIterator>
inline ForwordIterator __uninitlize_copy_aux(InputIterator first,
InputIterator end, ForwordIterator result, __false_type) {
while (first != end) {
std::cout << "first = " << *first << std::endl;
std::cout << "result = " << &*result << std::endl;
construct(&*result, *first);
++first;
++result;
}
return result;
}
template <class InputIterator, class ForwordIterator, class T>
inline ForwordIterator __uninitlize_copy(InputIterator first,
InputIterator end, ForwordIterator result, T*) {
typedef typename __true_traits<T>::is_POD_type is_POD;
return __uninitlize_copy_aux(first, end, result, is_POD());
}
template <class inputIterator, class ForwordIterator>
inline ForwordIterator uninitlize_copy(inputIterator first,
inputIterator end, ForwordIterator result) {
return __uninitlize_copy(first, end, result, value_type(result));
}
inline char* uninitlize_copy(const char* first, const char* end, char* result)
{
memmove(result, first, end - first);
return result + (end - first);
}
inline wchar_t* uninitlize_copy(const wchar_t* first, const wchar_t* end, wchar_t* result)
{
memmove(result, first, end - first);
return result + (end - first);
}
//´Ófirst¿ªÊ¼n¸öÔªËØÌî³ä³ÉxÖµ
template <typename InputIterator, typename T>
void __uninitlize_fill_aux(InputIterator first, InputIterator end,
const T& value, __true_type) {
while (first != end) {
*first = value;
++first;
}
}
template <typename InputIterator, typename T>
void __uninitlize_fill_aux(InputIterator first, InputIterator end,
const T& value, __false_type) {
while (first != end) {
construct(&*first, value);
++first;
}
}
template <typename InputIterator, typename T, typename U>
inline void __uninitlize_fill(InputIterator first, InputIterator end,
const T& value, U*) {
typedef typename __true_traits<U>::is_POD_type is_POD;
__uninitlize_fill_aux(first, end, value, is_POD());
}
template <typename InputIterator, typename T>
void uninitlize_fill(InputIterator first, InputIterator end, const T& value) {
__uninitlize_fill(first, end, value, value_type(first));
}
template<typename InputIterator, typename Size, typename T>
InputIterator __uninitlize_fill_n_aux(InputIterator first, Size n, const T& value,
__true_type) {
InputIterator cur = first;
while (n > 0) {
*cur = value;
++cur;
--n;
}
return cur;
}
template<typename InputIterator, typename Size, typename T>
InputIterator __uninitlize_fill_n_aux(InputIterator first, Size n, const T& value,
__false_type) {
InputIterator cur = first;
while (n > 0) {
construct(&*cur, value);
++cur;
--n;
}
return cur;
}
template<typename InputIterator, typename Size, typename T, typename U>
InputIterator __uninitlize_fill_n(InputIterator first, Size n, const T& value, U*) {
typedef typename __true_traits<U>::is_POD_type is_POD;
return __uninitlize_fill_n_aux(first, n, value, is_POD());
}
template <class InputIterator, class Size, class T>
inline InputIterator uninitlize_fill_n(InputIterator first, Size end,
const T& x) {
return __uninitlize_fill_n(first, end, x, value_type(first));
}
}