1 /* 2 * intlist.h 3 * 4 * Beispielprogramm eingebettete Klassen. 5 * Variante mit const_iterator und Iterator-Hilfstypen fuer std-Algorithmen. 6 * 7 * Autor: H.Drachenfels 8 * Erstellt am: 6.5.2021 9 */
10 #ifndef INTLIST_H
11 #define INTLIST_H
12
13 #include <iterator>
14
15 class intlist final
16 {
17 private:
18 class element;
19 element *head;
20
21 public:
22 intlist();
23 ~intlist();
24 // Entity-Klasse ohne Kopier- und Move-Semantik
25 intlist(const intlist&) = delete;
26 intlist& operator=(const intlist&) = delete;
27 intlist(intlist&&) = delete;
28 intlist& operator=(intlist&&) = delete;
29
30 intlist& insert(int);
31
32 class iterator final
33 {
34 private:
35 element *current;
36 explicit iterator(element*);
37 public:
38 bool operator!=(const iterator&) const;
39 int& operator*() const;
40 iterator& operator++();
41
42 friend class intlist;
43
44 typedef std::input_iterator_tag iterator_category;
45 typedef int value_type;
46 typedef std::ptrdiff_t difference_type;
47 typedef int* pointer;
48 typedef int& reference;
49 };
50
51 iterator begin();
52 iterator end();
53
54 class const_iterator final
55 {
56 private:
57 const element *current;
58 explicit const_iterator(const element*);
59 public:
60 bool operator!=(const const_iterator&) const;
61 const int& operator*() const;
62 const_iterator& operator++();
63
64 friend class intlist;
65
66 typedef std::input_iterator_tag iterator_category;
67 typedef const int value_type;
68 typedef std::ptrdiff_t difference_type;
69 typedef const int* pointer;
70 typedef const int& reference;
71 };
72
73 const_iterator begin() const;
74 const_iterator end() const;
75 const_iterator cbegin() const;
76 const_iterator cend() const;
77 };
78
79 #endif
80