src/containers.h

changeset 75
bf8c57437231
parent 73
1ee9b312dc18
child 82
841562f5a32f
equal deleted inserted replaced
74:007fbadfa7f9 75:bf8c57437231
37 #include <initializer_list> 37 #include <initializer_list>
38 38
39 template<class T> class list 39 template<class T> class list
40 { 40 {
41 public: 41 public:
42 typedef typename ::std::deque<T> list_type; 42 using list_type = typename ::std::deque<T>;
43 typedef typename list_type::iterator it; 43 using iterator = typename list_type::iterator;
44 typedef typename list_type::const_iterator c_it; 44 using const_iterator = typename list_type::const_iterator;
45 typedef typename list_type::reverse_iterator r_it; 45 using reverse_iterator = typename list_type::reverse_iterator;
46 typedef typename list_type::const_reverse_iterator cr_it; 46 using const_reverse_iterator = typename list_type::const_reverse_iterator;
47 typedef T element_type; 47 using element_type = T;
48 typedef list<T> self_type; 48 using self_type = list<T>;
49 49
50 // ===================================================================== 50 // =====================================================================
51 // 51 //
52 list() {} 52 list() {}
53 53
63 list (const list_type& a) : 63 list (const list_type& a) :
64 m_data (a) {} 64 m_data (a) {}
65 65
66 // ===================================================================== 66 // =====================================================================
67 // 67 //
68 it begin() 68 iterator begin()
69 { 69 {
70 return m_data.begin(); 70 return m_data.begin();
71 } 71 }
72 72
73 // ===================================================================== 73 // =====================================================================
74 // 74 //
75 c_it begin() const 75 const_iterator begin() const
76 { 76 {
77 return m_data.cbegin(); 77 return m_data.cbegin();
78 } 78 }
79 79
80 // ===================================================================== 80 // =====================================================================
81 // 81 //
82 it end() 82 iterator end()
83 { 83 {
84 return m_data.end(); 84 return m_data.end();
85 } 85 }
86 86
87 // ===================================================================== 87 // =====================================================================
88 // 88 //
89 c_it end() const 89 const_iterator end() const
90 { 90 {
91 return m_data.cend(); 91 return m_data.cend();
92 } 92 }
93 93
94 // ===================================================================== 94 // =====================================================================
95 // 95 //
96 r_it rbegin() 96 reverse_iterator rbegin()
97 { 97 {
98 return m_data.rbegin(); 98 return m_data.rbegin();
99 } 99 }
100 100
101 // ===================================================================== 101 // =====================================================================
102 // 102 //
103 cr_it crbegin() const 103 const_reverse_iterator crbegin() const
104 { 104 {
105 return m_data.crbegin(); 105 return m_data.crbegin();
106 } 106 }
107 107
108 // ===================================================================== 108 // =====================================================================
109 // 109 //
110 r_it rend() 110 reverse_iterator rend()
111 { 111 {
112 return m_data.rend(); 112 return m_data.rend();
113 } 113 }
114 114
115 // ===================================================================== 115 // =====================================================================
116 // 116 //
117 cr_it crend() const 117 const_reverse_iterator crend() const
118 { 118 {
119 return m_data.crend(); 119 return m_data.crend();
120 } 120 }
121 121
122 // ===================================================================== 122 // =====================================================================
215 void makeUnique() 215 void makeUnique()
216 { 216 {
217 // Remove duplicate entries. For this to be effective, the vector must be 217 // Remove duplicate entries. For this to be effective, the vector must be
218 // sorted first. 218 // sorted first.
219 sort(); 219 sort();
220 it pos = std::unique (begin(), end()); 220 iterator pos = std::unique (begin(), end());
221 resize (std::distance (begin(), pos)); 221 resize (std::distance (begin(), pos));
222 } 222 }
223 223
224 // ===================================================================== 224 // =====================================================================
225 // 225 //
258 std::sort (begin(), end()); 258 std::sort (begin(), end());
259 } 259 }
260 260
261 // ===================================================================== 261 // =====================================================================
262 // 262 //
263 int find (const element_type& needle) 263 int find (const element_type& needle) const
264 { 264 {
265 int i = 0; 265 int i = 0;
266 266
267 for (const element_type & hay : *this) 267 for (const element_type& hay : *this)
268 { 268 {
269 if (hay == needle) 269 if (hay == needle)
270 return i; 270 return i;
271 271
272 i++; 272 i++;

mercurial