1 | /*
|
---|
2 | * Copyright (c) 2017 Jaroslav Jindrak
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef LIBCPP_DEQUE
|
---|
30 | #define LIBCPP_DEQUE
|
---|
31 |
|
---|
32 | #include <initializer_list>
|
---|
33 | #include <memory>
|
---|
34 |
|
---|
35 | namespace std
|
---|
36 | {
|
---|
37 |
|
---|
38 | namespace aux
|
---|
39 | {
|
---|
40 | template<class T, class Allocator>
|
---|
41 | class deque_iterator
|
---|
42 | {
|
---|
43 | // TODO: implement
|
---|
44 | };
|
---|
45 |
|
---|
46 | template<class T, class Allocator>
|
---|
47 | class deque_const_iterator
|
---|
48 | {
|
---|
49 | // TODO: implement
|
---|
50 | };
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * 23.3.3 deque:
|
---|
55 | */
|
---|
56 |
|
---|
57 | template<class T, class Allocator = allocator<T>>
|
---|
58 | class deque
|
---|
59 | {
|
---|
60 | public:
|
---|
61 | using allocator_type = Allocator;
|
---|
62 | using value_type = T;
|
---|
63 | using reference = value_type&;
|
---|
64 | using const_reference = const value_type&;
|
---|
65 |
|
---|
66 | using iterator = aux::deque_iterator<T, Allocator>;
|
---|
67 | using const_iterator = aux::deque_const_iterator<T, Allocator>;
|
---|
68 | using reverse_iterator = std::reverse_iterator<iterator>;
|
---|
69 | using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
---|
70 |
|
---|
71 | using size_type = typename allocator_traits<allocator_type>::size_type;
|
---|
72 | using difference_type = typename allocator_traits<allocator_type>::difference_type;
|
---|
73 | using pointer = typename allocator_traits<allocator_type>::pointer;
|
---|
74 | using const_pointer = typename allocator_traits<allocator_type>::const_pointer;
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * 23.3.3.2, construct/copy/destroy:
|
---|
78 | */
|
---|
79 |
|
---|
80 | deque()
|
---|
81 | : deque{allocator_type{}}
|
---|
82 | { /* DUMMY BODY */ }
|
---|
83 |
|
---|
84 | explicit deque(const allocator_type& alloc)
|
---|
85 | {
|
---|
86 | // TODO: implement
|
---|
87 | }
|
---|
88 |
|
---|
89 | explicit deque(size_type n, const allocator_type& alloc = allocator_type{})
|
---|
90 | {
|
---|
91 | // TODO: implement
|
---|
92 | }
|
---|
93 |
|
---|
94 | deque(size_type n, const value_type& value, const allocator_type& alloc = allocator_type{})
|
---|
95 | {
|
---|
96 | // TODO: implement
|
---|
97 | }
|
---|
98 |
|
---|
99 | template<class InputIterator>
|
---|
100 | deque(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type{})
|
---|
101 | {
|
---|
102 | // TODO: implement
|
---|
103 | }
|
---|
104 |
|
---|
105 | deque(const deque& other)
|
---|
106 | {
|
---|
107 | // TODO: implement
|
---|
108 | }
|
---|
109 |
|
---|
110 | deque(deque&& other)
|
---|
111 | {
|
---|
112 | // TODO: implement
|
---|
113 | }
|
---|
114 |
|
---|
115 | deque(const deque& other, const allocator_type& alloc)
|
---|
116 | {
|
---|
117 | // TODO: implement
|
---|
118 | }
|
---|
119 |
|
---|
120 | deque(deque&& other, const allocator_type& alloc)
|
---|
121 | {
|
---|
122 | // TODO: implement
|
---|
123 | }
|
---|
124 |
|
---|
125 | deque(initializer_list<T> init, const allocator_type& alloc = allocator_type{})
|
---|
126 | {
|
---|
127 | // TODO: implement
|
---|
128 | }
|
---|
129 |
|
---|
130 | ~deque()
|
---|
131 | {
|
---|
132 | // TODO: implement
|
---|
133 | }
|
---|
134 |
|
---|
135 | deque& operator=(const deque& other)
|
---|
136 | {
|
---|
137 | // TODO: implement
|
---|
138 | }
|
---|
139 |
|
---|
140 | deque& operator=(deque&& other)
|
---|
141 | noexcept(allocator_traits<allocator_type>::is_always_equal::value)
|
---|
142 | {
|
---|
143 | // TODO: implement
|
---|
144 | }
|
---|
145 |
|
---|
146 | deque& operator=(initializer_list<T> init)
|
---|
147 | {
|
---|
148 | // TODO: implement
|
---|
149 | }
|
---|
150 |
|
---|
151 | template<class InputIterator>
|
---|
152 | void assign(InputIterator first, InputIterator last)
|
---|
153 | {
|
---|
154 | // TODO: implement
|
---|
155 | }
|
---|
156 |
|
---|
157 | void assign(size_type n, const T& value)
|
---|
158 | {
|
---|
159 | // TODO: implement
|
---|
160 | }
|
---|
161 |
|
---|
162 | void assign(initializer_list<T> init)
|
---|
163 | {
|
---|
164 | // TODO: implement
|
---|
165 | }
|
---|
166 |
|
---|
167 | allocator_type get_allocator() const noexcept
|
---|
168 | {
|
---|
169 | return allocator_;
|
---|
170 | }
|
---|
171 |
|
---|
172 | iterator begin() noexcept
|
---|
173 | {
|
---|
174 | // TODO: implement
|
---|
175 | }
|
---|
176 |
|
---|
177 | const_iterator begin() const noexcept
|
---|
178 | {
|
---|
179 | // TODO: implement
|
---|
180 | }
|
---|
181 |
|
---|
182 | iterator end() noexcept
|
---|
183 | {
|
---|
184 | // TODO: implement
|
---|
185 | }
|
---|
186 |
|
---|
187 | const_iterator end() const noexcept
|
---|
188 | {
|
---|
189 | // TODO: implement
|
---|
190 | }
|
---|
191 |
|
---|
192 | reverse_iterator rbegin() noexcept
|
---|
193 | {
|
---|
194 | // TODO: implement
|
---|
195 | }
|
---|
196 |
|
---|
197 | const_reverse_iterator rbegin() const noexcept
|
---|
198 | {
|
---|
199 | // TODO: implement
|
---|
200 | }
|
---|
201 |
|
---|
202 | reverse_iterator rend() noexcept
|
---|
203 | {
|
---|
204 | // TODO: implement
|
---|
205 | }
|
---|
206 |
|
---|
207 | const_reverse_iterator rend() const noexcept
|
---|
208 | {
|
---|
209 | // TODO: implement
|
---|
210 | }
|
---|
211 |
|
---|
212 | const_iterator cbegin() const noexcept
|
---|
213 | {
|
---|
214 | // TODO: implement
|
---|
215 | }
|
---|
216 |
|
---|
217 | const_iterator cend() const noexcept
|
---|
218 | {
|
---|
219 | // TODO: implement
|
---|
220 | }
|
---|
221 |
|
---|
222 | const_reverse_iterator crbegin() const noexcept
|
---|
223 | {
|
---|
224 | // TODO: implement
|
---|
225 | }
|
---|
226 |
|
---|
227 | const_reverse_iterator crend() const noexcept
|
---|
228 | {
|
---|
229 | // TODO: implement
|
---|
230 | }
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * 23.3.3.3, capacity:
|
---|
234 | */
|
---|
235 |
|
---|
236 | size_type size() const noexcept
|
---|
237 | {
|
---|
238 | // TODO: implement
|
---|
239 | }
|
---|
240 |
|
---|
241 | size_type max_size() const noexcept
|
---|
242 | {
|
---|
243 | // TODO: implement
|
---|
244 | }
|
---|
245 |
|
---|
246 | void resize(size_type sz)
|
---|
247 | {
|
---|
248 | // TODO: implement
|
---|
249 | }
|
---|
250 |
|
---|
251 | void resize(size_type sz, const value_type& value)
|
---|
252 | {
|
---|
253 | // TODO: implement
|
---|
254 | }
|
---|
255 |
|
---|
256 | void shrink_to_fit()
|
---|
257 | {
|
---|
258 | // TODO: implement
|
---|
259 | }
|
---|
260 |
|
---|
261 | bool empty() const noexcept
|
---|
262 | {
|
---|
263 | // TODO: implement
|
---|
264 | }
|
---|
265 |
|
---|
266 | reference operator[](size_type idx)
|
---|
267 | {
|
---|
268 | // TODO: implement
|
---|
269 | }
|
---|
270 |
|
---|
271 | const_reference operator[](size_type idx)
|
---|
272 | {
|
---|
273 | // TODO: implement
|
---|
274 | }
|
---|
275 |
|
---|
276 | reference at(size_type idx)
|
---|
277 | {
|
---|
278 | // TODO: implement
|
---|
279 | }
|
---|
280 |
|
---|
281 | const_reference at(size_type idx)
|
---|
282 | {
|
---|
283 | // TODO: implement
|
---|
284 | }
|
---|
285 |
|
---|
286 | reference front()
|
---|
287 | {
|
---|
288 | // TODO: implement
|
---|
289 | }
|
---|
290 |
|
---|
291 | const_reference front() const
|
---|
292 | {
|
---|
293 | // TODO: implement
|
---|
294 | }
|
---|
295 |
|
---|
296 | reference back()
|
---|
297 | {
|
---|
298 | // TODO: implement
|
---|
299 | }
|
---|
300 |
|
---|
301 | const_reference back() const
|
---|
302 | {
|
---|
303 | // TODO: implement
|
---|
304 | }
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * 23.3.3.4, modifiers:
|
---|
308 | */
|
---|
309 |
|
---|
310 | template<class... Args>
|
---|
311 | void emplace_front(Args&&... args)
|
---|
312 | {
|
---|
313 | // TODO: implement
|
---|
314 | }
|
---|
315 |
|
---|
316 | template<class... Args>
|
---|
317 | void emplace_back(Args&&... args)
|
---|
318 | {
|
---|
319 | // TODO: implement
|
---|
320 | }
|
---|
321 |
|
---|
322 | template<class... Args>
|
---|
323 | iterator emplace(const_iterator position, Args&&... args)
|
---|
324 | {
|
---|
325 | // TODO: implement
|
---|
326 | }
|
---|
327 |
|
---|
328 | void push_front(const value_type& value)
|
---|
329 | {
|
---|
330 | // TODO: implement
|
---|
331 | }
|
---|
332 |
|
---|
333 | void push_front(value_type&& value)
|
---|
334 | {
|
---|
335 | // TODO: implement
|
---|
336 | }
|
---|
337 |
|
---|
338 | void push_back(const value_type& value)
|
---|
339 | {
|
---|
340 | // TODO: implement
|
---|
341 | }
|
---|
342 |
|
---|
343 | void push_back(value_type&& value)
|
---|
344 | {
|
---|
345 | // TODO: implement
|
---|
346 | }
|
---|
347 |
|
---|
348 | iterator insert(const_iterator position, const value_type& value)
|
---|
349 | {
|
---|
350 | // TODO: implement
|
---|
351 | }
|
---|
352 |
|
---|
353 | iterator insert(const_iterator position, value_type&& value)
|
---|
354 | {
|
---|
355 | // TODO: implement
|
---|
356 | }
|
---|
357 |
|
---|
358 | iterator insert(const_iterator position, size_type n, const value_type& value)
|
---|
359 | {
|
---|
360 | // TODO: implement
|
---|
361 | }
|
---|
362 |
|
---|
363 | template<class InputIterator>
|
---|
364 | iterator insert(const_iterator position, InputIterator first, InputIterator last)
|
---|
365 | {
|
---|
366 | // TODO: implement
|
---|
367 | }
|
---|
368 |
|
---|
369 | iterator insert(const_iterator position, initializer_list<value_type> init)
|
---|
370 | {
|
---|
371 | // TODO: implement
|
---|
372 | }
|
---|
373 |
|
---|
374 | void pop_back()
|
---|
375 | {
|
---|
376 | // TODO: implement
|
---|
377 | }
|
---|
378 |
|
---|
379 | void pop_front()
|
---|
380 | {
|
---|
381 | // TODO: implement
|
---|
382 | }
|
---|
383 |
|
---|
384 | iterator erase(const_iterator position)
|
---|
385 | {
|
---|
386 | // TODO: implement
|
---|
387 | }
|
---|
388 |
|
---|
389 | iterator eraser(cosnt_iteterator first, const_iterator last)
|
---|
390 | {
|
---|
391 | // TODO: implement
|
---|
392 | }
|
---|
393 |
|
---|
394 | void swap(deque& other)
|
---|
395 | noexcept(allocator_traits<allocator_type>::is_always_equal::value)
|
---|
396 | {
|
---|
397 | // TODO: implement
|
---|
398 | }
|
---|
399 |
|
---|
400 | void clear() noexcept
|
---|
401 | {
|
---|
402 | // TODO: implement
|
---|
403 | }
|
---|
404 |
|
---|
405 | private:
|
---|
406 | allocator_type allocator_;
|
---|
407 |
|
---|
408 | size_type front_bucket_idx_;
|
---|
409 | size_type back_bucket_idx_;
|
---|
410 |
|
---|
411 | static constexpr size_type bucket_size_{16};
|
---|
412 |
|
---|
413 | size_type bucket_count_;
|
---|
414 | size_type bucket_capacity_;
|
---|
415 |
|
---|
416 | value_type** data_;
|
---|
417 | };
|
---|
418 |
|
---|
419 | template<class T, class Allocator>
|
---|
420 | bool operator==(const deque<T, Allocator>& lhs, const deque<T, Allocator>& rhs)
|
---|
421 | {
|
---|
422 | // TODO: implement
|
---|
423 | }
|
---|
424 |
|
---|
425 | template<class T, class Allocator>
|
---|
426 | bool operator<(const deque<T, Allocator>& lhs, const deque<T, Allocator>& rhs)
|
---|
427 | {
|
---|
428 | // TODO: implement
|
---|
429 | }
|
---|
430 |
|
---|
431 | template<class T, class Allocator>
|
---|
432 | bool operator=!(const deque<T, Allocator>& lhs, const deque<T, Allocator>& rhs)
|
---|
433 | {
|
---|
434 | // TODO: implement
|
---|
435 | }
|
---|
436 |
|
---|
437 | template<class T, class Allocator>
|
---|
438 | bool operator>(const deque<T, Allocator>& lhs, const deque<T, Allocator>& rhs)
|
---|
439 | {
|
---|
440 | // TODO: implement
|
---|
441 | }
|
---|
442 |
|
---|
443 | template<class T, class Allocator>
|
---|
444 | bool operator<=(const deque<T, Allocator>& lhs, const deque<T, Allocator>& rhs)
|
---|
445 | {
|
---|
446 | // TODO: implement
|
---|
447 | }
|
---|
448 |
|
---|
449 | template<class T, class Allocator>
|
---|
450 | bool operator>=(const deque<T, Allocator>& lhs, const deque<T, Allocator>& rhs)
|
---|
451 | {
|
---|
452 | // TODO: implement
|
---|
453 | }
|
---|
454 |
|
---|
455 | /**
|
---|
456 | * 23.3.3.5, deque specialized algorithms:
|
---|
457 | */
|
---|
458 |
|
---|
459 | template<class T, class Allocator>
|
---|
460 | void swap(deque<T, Allocator>& lhs, deque<T, Allocator>& rhs)
|
---|
461 | noexcept(noexcept(lhs.swap(rhs)))
|
---|
462 | {
|
---|
463 | lhs.swap(rhs);
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | #endif
|
---|