Debian Codegraph @

headers/iterator

raw
1 /* Copyright (C) 2015 Povilas Kanapickas <[email protected]>
2
3 This file is part of cppreference-doc
4
5 This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
6 Unported License. To view a copy of this license, visit
7 http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
8 Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
9
10 Permission is granted to copy, distribute and/or modify this document
11 under the terms of the GNU Free Documentation License, Version 1.3 or
12 any later version published by the Free Software Foundation; with no
13 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
14 */
15
16 #ifndef CPPREFERENCE_ITERATOR_H
17 #define CPPREFERENCE_ITERATOR_H
18
19 namespace std {
20
21 // SIMPLIFIED: template specializations are not supported, so the typedefs use
22 // the T* specialization
23 template<class Iterator>
24 struct iterator_traits {
25 #if CPPREFERENCE_SIMPLIFY_TYPEDEFS
26 typedef ptrdiff_t difference_type;
27 typedef T value_type;
28 typedef T* pointer;
29 typedef T& reference;
30 typedef random_access_iterator_tag iterator_category;
31 #else
32 typedef typename Iterator::difference_type difference_type;
33 typedef typename Iterator::value_type value_type;
34 typedef typename Iterator::pointer pointer;
35 typedef typename Iterator::reference reference;
36 typedef typename Iterator::iterator_category iterator_category;
37 #endif
38 };
39
40 struct input_iterator_tag { };
41 struct output_iterator_tag { };
42 struct forward_iterator_tag : public input_iterator_tag { };
43 struct bidirectional_iterator_tag : public forward_iterator_tag { };
44 struct random_access_iterator_tag : public bidirectional_iterator_tag { };
45
46 template<class Category, class T, class Distance = ptrdiff_t,
47 class Pointer = T*, class Reference = T&>
48 struct iterator {
49 typedef T value_type;
50 typedef Distance difference_type;
51 typedef Pointer pointer;
52 typedef Reference reference;
53 typedef Category iterator_category;
54 };
55
56 template <class Iterator>
57 class reverse_iterator { // SIMPLIFIED: does not inherit iterator
58 public:
59 typedef Iterator iterator_type;
60 #if CPPREFERENCE_SIMPLIFY_TYPEDEFS
61 typedef typename ptrdiff_t difference_type;
62 typedef typename Iterator::value_type value_type;
63 typedef typename Iterator::pointer pointer;
64 typedef typename Iterator::reference reference;
65 typedef typename Iterator::iterator_category iterator_category;
66 #else
67 typedef typename iterator_traits<Iterator>::value_type value_type;
68 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
69 typedef typename iterator_traits<Iterator>::difference_type difference_type;
70 typedef typename iterator_traits<Iterator>::reference reference;
71 typedef typename iterator_traits<Iterator>::pointer pointer;
72 #endif
73
74 reverse_iterator();
75 explicit reverse_iterator(Iterator x);
76 template <class U> reverse_iterator(const reverse_iterator<U>& other);
77
78 template<class U>
79 reverse_iterator& operator=(const reverse_iterator<U>& other);
80
81 Iterator base() const;
82 reference operator*() const;
83 pointer operator->() const;
84 reference operator[](difference_type n) const; // actually unspecified
85
86 reverse_iterator& operator++();
87 reverse_iterator& operator--();
88 reverse_iterator operator++(int);
89 reverse_iterator operator--(int);
90 reverse_iterator operator+(difference_type n) const;
91 reverse_iterator operator-(difference_type n) const;
92 reverse_iterator& operator+=(difference_type n);
93 reverse_iterator& operator-=(difference_type n);
94 protected:
95 Iterator current;
96 };
97
98 template<class Iterator1, class Iterator2 >
99 bool operator==(const reverse_iterator<Iterator1>& lhs,
100 const reverse_iterator<Iterator2>& rhs);
101
102 template<class Iterator1, class Iterator2 >
103 bool operator!=(const reverse_iterator<Iterator1>& lhs,
104 const reverse_iterator<Iterator2>& rhs);
105
106 template<class Iterator1, class Iterator2 >
107 bool operator<(const reverse_iterator<Iterator1>& lhs,
108 const reverse_iterator<Iterator2>& rhs);
109
110 template<class Iterator1, class Iterator2 >
111 bool operator<=(const reverse_iterator<Iterator1>& lhs,
112 const reverse_iterator<Iterator2>& rhs);
113
114 template<class Iterator1, class Iterator2 >
115 bool operator>(const reverse_iterator<Iterator1>& lhs,
116 const reverse_iterator<Iterator2>& rhs);
117
118 template<class Iterator1, class Iterator2 >
119 bool operator>=(const reverse_iterator<Iterator1>& lhs,
120 const reverse_iterator<Iterator2>& rhs);
121
122 template<class Iterator >
123 reverse_iterator<Iterator>
124 operator+(typename reverse_iterator<Iterator>::difference_type n,
125 const reverse_iterator<Iterator>& it);
126
127 template<class Iterator >
128 typename reverse_iterator<Iterator>::difference_type
129 operator-(const reverse_iterator<Iterator>& lhs,
130 const reverse_iterator<Iterator>& rhs);
131
132 #if CPPREFERENCE_STDVER >= 2011
133 template <class Iterator>
134 class move_iterator {
135 public:
136 typedef Iterator iterator_type;
137 typedef Iterator pointer;
138 typedef value_type&& reference;
139 #if CPPREFERENCE_SIMPLIFY_TYPEDEFS
140 typedef typename ptrdiff_t difference_type;
141 typedef typename Iterator::iterator_category iterator_category;
142 #else
143 typedef typename iterator_traits<Iterator>::difference_type difference_type;
144 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
145 #endif
146
147 move_iterator();
148 explicit move_iterator(Iterator x);
149 template <class U> move_iterator(const move_iterator<U>& other);
150
151 template<class U>
152 move_iterator& operator=(const move_iterator<U>& other);
153
154 Iterator base() const;
155 reference operator*() const;
156 pointer operator->() const;
157 reference operator[](difference_type n) const; // actually unspecified
158
159 move_iterator& operator++();
160 move_iterator& operator--();
161 move_iterator operator++(int);
162 move_iterator operator--(int);
163 move_iterator operator+(difference_type n) const;
164 move_iterator operator-(difference_type n) const;
165 move_iterator& operator+=(difference_type n);
166 move_iterator& operator-=(difference_type n);
167 };
168
169
170 template<class Iterator1, class Iterator2 >
171 bool operator==(const move_iterator<Iterator1>& lhs,
172 const move_iterator<Iterator2>& rhs);
173
174 template<class Iterator1, class Iterator2 >
175 bool operator!=(const move_iterator<Iterator1>& lhs,
176 const move_iterator<Iterator2>& rhs);
177
178 template<class Iterator1, class Iterator2 >
179 bool operator<(const move_iterator<Iterator1>& lhs,
180 const move_iterator<Iterator2>& rhs);
181
182 template<class Iterator1, class Iterator2 >
183 bool operator<=(const move_iterator<Iterator1>& lhs,
184 const move_iterator<Iterator2>& rhs);
185
186 template<class Iterator1, class Iterator2 >
187 bool operator>(const move_iterator<Iterator1>& lhs,
188 const move_iterator<Iterator2>& rhs);
189
190 template<class Iterator1, class Iterator2 >
191 bool operator>=(const move_iterator<Iterator1>& lhs,
192 const move_iterator<Iterator2>& rhs);
193
194 template<class Iterator >
195 move_iterator<Iterator>
196 operator+(typename move_iterator<Iterator>::difference_type n,
197 const move_iterator<Iterator>& it);
198
199 template<class Iterator >
200 typename move_iterator<Iterator>::difference_type
201 operator-(const move_iterator<Iterator>& lhs,
202 const move_iterator<Iterator>& rhs);
203
204 #endif // CPPREFERENCE_STDVER >= 2011
205
206 template<class Container>
207 class back_insert_iterator { // SIMPLIFIED: does not inherit iterator
208 public:
209 typedef void value_type;
210 typedef void difference_type;
211 typedef void pointer;
212 typedef void reference;
213 typedef output_iterator_tag iterator_category;
214
215 typedef Container container_type;
216
217 explicit back_insert_iterator(Container& c);
218
219 #if CPPREFERENCE_STDVER <2011
220 back_insert_iterator<Container>&
221 operator=(typename Container::const_reference value);
222 #else
223 back_insert_iterator<Container>&
224 operator=(const typename Container::value_type& value);
225 #endif
226 back_insert_iterator<Container>&
227 operator=(typename Container::value_type&& value);
228 back_insert_iterator& operator*();
229 back_insert_iterator& operator++();
230 back_insert_iterator& operator++(int);
231 protected:
232 Container* container;
233 };
234
235 template<class Container>
236 class front_insert_iterator { // SIMPLIFIED: does not inherit iterator
237 public:
238 typedef void value_type;
239 typedef void difference_type;
240 typedef void pointer;
241 typedef void reference;
242 typedef output_iterator_tag iterator_category;
243
244 typedef Container container_type;
245
246 explicit front_insert_iterator(Container& c);
247
248 #if CPPREFERENCE_STDVER <2011
249 front_insert_iterator<Container>&
250 operator=(typename Container::const_reference value);
251 #else
252 front_insert_iterator<Container>&
253 operator=(const typename Container::value_type& value);
254 #endif
255 front_insert_iterator<Container>&
256 operator=(typename Container::value_type&& value);
257 front_insert_iterator& operator*();
258 front_insert_iterator& operator++();
259 front_insert_iterator& operator++(int);
260 protected:
261 Container* container;
262 };
263
264 template<class Container>
265 class insert_iterator { // SIMPLIFIED: does not inherit iterator
266 public:
267 typedef void value_type;
268 typedef void difference_type;
269 typedef void pointer;
270 typedef void reference;
271 typedef output_iterator_tag iterator_category;
272
273 typedef Container container_type;
274
275 explicit insert_iterator(Container& c, typename Container::iterator i);
276
277 #if CPPREFERENCE_STDVER <2011
278 insert_iterator<Container>&
279 operator=(typename Container::const_reference value);
280 #else
281 insert_iterator<Container>&
282 operator=(const typename Container::value_type& value);
283 #endif
284 insert_iterator<Container>&
285 operator=(typename Container::value_type&& value);
286 insert_iterator& operator*();
287 insert_iterator& operator++();
288 insert_iterator& operator++(int);
289 protected:
290 Container* container;
291 Container::iterator iter;
292 };
293
294 template<class T,
295 class CharT = char,
296 class Traits = std::char_traits<CharT>,
297 class Distance = std::ptrdiff_t >
298 class istream_iterator { // SIMPLIFIED: does not inherit iterator
299 public:
300 typedef CharT char_type;
301 typedef Traits traits_type;
302 typedef std::basic_istream<CharT, Traits> istream_type;
303
304 typedef T value_type;
305 typedef Distance difference_type;
306 typedef const T* pointer;
307 typedef const T& reference;
308 typedef input_iterator_tag iterator_category;
309
310 istream_iterator();
311
312 istream_iterator(istream_type& stream);
313
314 istream_iterator(const istream_iterator& other) = default;
315
316 const T& operator*() const;
317 const T* operator->() const;
318
319 istream_iterator& operator++();
320 istream_iterator operator++(int);
321 };
322
323 template<class T, class CharT, class Traits, class Dist >
324 bool operator==(const istream_iterator<T, CharT, Traits, Dist>& lhs,
325 const istream_iterator<T, CharT, Traits, Dist>& rhs);
326
327 template<class CharT, class Traits >
328 bool operator!=(const istream_iterator<T, CharT, Traits, Dist>& lhs,
329 const istream_iterator<T, CharT, Traits, Dist>& rhs);
330
331
332 template<class T,
333 class CharT = char,
334 class Traits = std::char_traits<CharT> >
335 class ostream_iterator { // SIMPLIFIED: does not inherit iterator
336 public:
337 typedef CharT char_type;
338 typedef Traits traits_type;
339 typedef std::basic_ostream<CharT, Traits> ostream_type;
340
341 typedef void value_type;
342 typedef void difference_type;
343 typedef void pointer;
344 typedef void reference;
345 typedef output_iterator_tag iterator_category;
346
347 ostream_iterator(ostream_type& stream);
348 ostream_iterator(ostream_type& stream, const CharT* delim);
349 ~ostream_iterator();
350
351 ostream_iterator& operator=(const T& value);
352 ostream_iterator& operator*();
353 ostream_iterator& operator++();
354 ostream_iterator& operator++(int);
355 };
356
357 template<class T, class CharT, class Traits >
358 bool operator==(const ostream_iterator<T, CharT, Traits>& lhs,
359 const ostream_iterator<T, CharT, Traits>& rhs);
360
361 template<class CharT, class Traits >
362 bool operator!=(const ostream_iterator<T, CharT, Traits>& lhs,
363 const ostream_iterator<T, CharT, Traits>& rhs);
364
365
366 template<class CharT, class Traits = std::char_traits<CharT> >
367 class istreambuf_iterator { // SIMPLIFIED: does not inherit iterator
368 public:
369 typedef CharT char_type;
370 typedef Traits traits_type;
371 #if CPPREFERENCE_SIMPLIFY_TYPEDEFS
372 typedef int int_type;
373 #else
374 typedef typename Traits::int_type int_type;
375 #endif
376 typedef std::basic_streambuf<CharT, Traits> streambuf_type;
377 typedef std::basic_istream<CharT, Traits> istream_type;
378
379 typedef T value_type;
380 typedef Distance difference_type;
381 typedef const T* pointer;
382 typedef const T& reference;
383 typedef input_iterator_tag iterator_category;
384
385 istreambuf_iterator();
386 istreambuf_iterator(std::basic_istream<CharT, Traits>& is);
387 istreambuf_iterator(std::basic_streambuf<CharT, Traits>* s);
388 istreambuf_iterator(const istreambuf_iterator&) = default;
389
390 CharT operator*() const;
391 #if CPPREFERENCE_STDVER >= 2011
392 pointer operator->() const;
393 #endif
394 istreambuf_iterator& operator++();
395 istreambuf_iterator operator++(int); // actually unspecified
396
397 bool equal(const istreambuf_iterator& it) const;
398 };
399
400 template<class CharT, class Traits >
401 bool operator==(const istreambuf_iterator<CharT, Traits>& lhs,
402 const istreambuf_iterator<CharT, Traits>& rhs);
403
404 template<class CharT, class Traits >
405 bool operator!=(const istreambuf_iterator<CharT, Traits>& lhs,
406 const istreambuf_iterator<CharT, Traits>& rhs);
407
408 template<class CharT,
409 class Traits = std::char_traits<CharT> >
410 class ostreambuf_iterator { // SIMPLIFIED: does not inherit iterator
411 public:
412 typedef CharT char_type;
413 typedef Traits traits_type;
414 typedef std::basic_streambuf<CharT, Traits> streambuf_type;
415 typedef std::basic_ostream<CharT, Traits> ostream_type;
416
417 typedef void value_type;
418 typedef void difference_type;
419 typedef void pointer;
420 typedef void reference;
421 typedef output_iterator_tag iterator_category;
422
423 ostreambuf_iterator(streambuf_type* buffer);
424 ostreambuf_iterator(ostream_type& stream);
425
426 ostreambuf_iterator& operator=(CharT c);
427 ostreambuf_iterator& operator*();
428 ostreambuf_iterator& operator++();
429 ostreambuf_iterator& operator++(int);
430 bool failed() const;
431 };
432
433 #if CPPREFERENCE_STDVER >= 2011 && CPPREFERENCE_STDVER <2014
434 template<class Iterator >
435 std::move_iterator<Iterator> make_move_iterator(const Iterator& i);
436 #elif CPPREFERENCE_STDVER >= 2014
437 template<class Iterator >
438 std::move_iterator<Iterator> make_move_iterator(Iterator i);
439
440 template <class Iterator>
441 std::reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
442 #endif
443
444 template<class Container >
445 std::front_insert_iterator<Container> front_inserter(Container& c);
446
447 template<class Container >
448 std::back_insert_iterator<Container> back_inserter(Container& c);
449
450 template<class Container >
451 std::insert_iterator<Container> inserter(Container& c, typename Container::iterator i);
452
453 template<class InputIt, class Distance >
454 void advance(InputIt& it, Distance n);
455
456 template<class InputIt >
457 typename std::iterator_traits<InputIt>::difference_type
458 distance(InputIt first, InputIt last);
459
460 #if CPPREFERENCE_STDVER >= 2011
461 template<class ForwardIt >
462 ForwardIt next(ForwardIt it,
463 typename std::iterator_traits<ForwardIt>::difference_type n = 1);
464
465 template<class BidirIt >
466 BidirIt prev(BidirIt it,
467 typename std::iterator_traits<BidirIt>::difference_type n = 1);
468
469 template<class C >
470 auto begin(C& c) -> decltype(c.begin());
471
472 template<class C >
473 auto begin(const C& c) -> decltype(c.begin());
474
475 template<class T, std::size_t N >
476 T* begin(T(&array)[N]);
477
478 template<class C >
479 auto end(C& c) -> decltype(c.end());
480
481 template<class C >
482 auto end(const C& c) -> decltype(c.end());
483
484 template<class T, std::size_t N >
485 T* end(T(&array)[N]);
486
487 #endif
488 #if CPPREFERENCE_STDVER >= 2014
489
490 template<class C >
491 constexpr auto cbegin(const C& c) -> decltype(std::begin(c));
492
493 template<class C >
494 constexpr auto cend(const C& c) -> decltype(std::end(c));
495
496 template<class C >
497 auto rbegin(C& c) -> decltype(c.rbegin());
498
499 template<class C >
500 auto rbegin(const C& c) -> decltype(c.rbegin());
501
502 template<class T, size_t N >
503 reverse_iterator<T*> rbegin(T(&array)[N]);
504
505 template<class C >
506 auto crbegin(const C& c) -> decltype(std::rbegin(c));
507
508 template<class C >
509 auto rend(C& c) -> decltype(c.rend());
510
511 template<class C >
512 auto rend(const C& c) -> decltype(c.rend());
513
514 template<class T, size_t N >
515 reverse_iterator<T*> rend(T(&array)[N]);
516
517 template<class C >
518 auto crend(const C& c) -> decltype(std::rend(c));
519
520 #endif // CPPREFERENCE_STDVER >= 2014
521
522 } // namespace std
523
524 #endif // CPPREFERENCE_ITERATOR_H