… | |
… | |
20 | return first; |
20 | return first; |
21 | } |
21 | } |
22 | |
22 | |
23 | #include <new> |
23 | #include <new> |
24 | |
24 | |
25 | #if __cplusplus >= 201103L |
25 | #if ECB_CPP11 |
26 | #include <type_traits> |
26 | #include <type_traits> |
27 | #endif |
27 | #endif |
28 | |
28 | |
29 | // original version taken from MICO, but this has been completely rewritten |
29 | // original version taken from MICO, but this has been completely rewritten |
30 | // known limitations w.r.t. std::vector |
30 | // known limitations w.r.t. std::vector |
… | |
… | |
37 | // - no bool specialisation |
37 | // - no bool specialisation |
38 | template<class T> |
38 | template<class T> |
39 | struct simplevec |
39 | struct simplevec |
40 | { |
40 | { |
41 | #if ESTL_BIG_VECTOR |
41 | #if ESTL_BIG_VECTOR |
42 | // shoudl use size_t/ssize_t, but that's not portable enough for us |
42 | // should use size_t/ssize_t, but that's not portable enough for us |
43 | typedef unsigned long size_type; |
43 | typedef unsigned long size_type; |
44 | typedef long difference_type; |
44 | typedef long difference_type; |
45 | #else |
45 | #else |
46 | typedef uint32_t size_type; |
46 | typedef uint32_t size_type; |
47 | typedef int32_t difference_type; |
47 | typedef int32_t difference_type; |
… | |
… | |
63 | |
63 | |
64 | // we shamelessly optimise for "simple" types. everything |
64 | // we shamelessly optimise for "simple" types. everything |
65 | // "not simple enough" will use the slow path. |
65 | // "not simple enough" will use the slow path. |
66 | static bool is_simple_enough () |
66 | static bool is_simple_enough () |
67 | { |
67 | { |
68 | return 1; // we are not there yet |
68 | #if ECB_CPP11 |
69 | #if __cplusplus >= 201103L |
|
|
70 | return std::is_trivially_assignable<T, T>::value |
69 | return std::is_trivially_assignable<T, T>::value |
71 | && std::is_trivially_constructable<T>::value |
70 | && std::is_trivially_constructable<T>::value |
72 | && std::is_trivially_copyable<T>::value |
71 | && std::is_trivially_copyable<T>::value |
73 | && std::is_trivially_destructible<T>::value; |
72 | && std::is_trivially_destructible<T>::value; |
74 | #elif ECB_GCC_VERSION(4,4) |
73 | #elif ECB_GCC_VERSION(4,4) |
… | |
… | |
83 | |
82 | |
84 | static void construct (iterator a, size_type n = 1) |
83 | static void construct (iterator a, size_type n = 1) |
85 | { |
84 | { |
86 | if (!is_simple_enough ()) |
85 | if (!is_simple_enough ()) |
87 | while (n--) |
86 | while (n--) |
88 | new (*a++) T (); |
87 | new (a++) T (); |
89 | } |
88 | } |
90 | |
89 | |
91 | static void destruct (iterator a, size_type n = 1) |
90 | static void destruct (iterator a, size_type n = 1) |
92 | { |
91 | { |
93 | if (!is_simple_enough ()) |
92 | if (!is_simple_enough ()) |
… | |
… | |
146 | buf = nbuf; |
145 | buf = nbuf; |
147 | } |
146 | } |
148 | |
147 | |
149 | construct (buf + sze, n); |
148 | construct (buf + sze, n); |
150 | |
149 | |
151 | sze += n; |
|
|
152 | |
|
|
153 | iterator src = buf + pos; |
150 | iterator src = buf + pos; |
154 | if (is_simple_enough ()) |
151 | if (is_simple_enough ()) |
155 | memmove (src + n, src, sizeof (T) * n); |
152 | memmove (src + n, src, sizeof (T) * (sze - pos)); |
156 | else |
153 | else |
157 | for (size_type i = n; i--; ) |
154 | for (size_type i = sze - pos; i--; ) |
158 | op (src + n + i, src + i); |
155 | cop_set (src + n + i, src + i); |
|
|
156 | |
|
|
157 | sze += n; |
159 | } |
158 | } |
160 | |
159 | |
161 | public: |
160 | public: |
162 | size_type capacity () const { return res; } |
161 | size_type capacity () const { return res; } |
163 | size_type size () const { return sze; } |
162 | size_type size () const { return sze; } |
… | |
… | |
217 | |
216 | |
218 | while (n--) |
217 | while (n--) |
219 | new (buf + n) T (t); |
218 | new (buf + n) T (t); |
220 | } |
219 | } |
221 | |
220 | |
222 | template<class I> |
221 | simplevec (const_iterator first, const_iterator last) |
223 | simplevec (I first, I last) |
|
|
224 | { |
222 | { |
225 | sze = res = last - first; |
223 | sze = res = last - first; |
226 | buf = alloc (sze); |
224 | buf = alloc (sze); |
227 | copy (buf, first, sze, cop_new); |
225 | copy (buf, first, sze, cop_new); |
228 | } |
226 | } |
… | |
… | |
268 | reference operator [](size_type idx) { return buf[idx]; } |
266 | reference operator [](size_type idx) { return buf[idx]; } |
269 | |
267 | |
270 | const_reference at (size_type idx) const { return buf [idx]; } |
268 | const_reference at (size_type idx) const { return buf [idx]; } |
271 | reference at (size_type idx) { return buf [idx]; } |
269 | reference at (size_type idx) { return buf [idx]; } |
272 | |
270 | |
273 | template<class I> |
271 | void assign (const_iterator first, const_iterator last) |
274 | void assign (I first, I last) |
|
|
275 | { |
272 | { |
276 | swap (simplevec<T> (first, last)); |
273 | simplevec<T> v (first, last); |
|
|
274 | swap (v); |
277 | } |
275 | } |
278 | |
276 | |
279 | void assign (size_type n, const T &t) |
277 | void assign (size_type n, const T &t) |
280 | { |
278 | { |
281 | swap (simplevec<T> (n, t)); |
279 | simplevec<T> v (n, t); |
|
|
280 | swap (v); |
282 | } |
281 | } |
283 | |
282 | |
284 | simplevec<T> &operator= (const simplevec<T> &v) |
283 | simplevec<T> &operator= (const simplevec<T> &v) |
285 | { |
284 | { |
286 | assign (v.begin (), v.end ()); |
285 | assign (v.begin (), v.end ()); |
… | |
… | |
295 | buf [at] = t; |
294 | buf [at] = t; |
296 | |
295 | |
297 | return buf + at; |
296 | return buf + at; |
298 | } |
297 | } |
299 | |
298 | |
300 | template<class I> |
|
|
301 | iterator insert (iterator pos, I first, I last) |
299 | iterator insert (iterator pos, const_iterator first, const_iterator last) |
302 | { |
300 | { |
303 | size_type n = last - first; |
301 | size_type n = last - first; |
304 | size_type at = pos - begin (); |
302 | size_type at = pos - begin (); |
305 | |
303 | |
306 | ins (pos, n); |
304 | ins (pos, n); |
… | |
… | |
319 | *i++ = t; |
317 | *i++ = t; |
320 | |
318 | |
321 | return buf + at; |
319 | return buf + at; |
322 | } |
320 | } |
323 | |
321 | |
324 | void erase (iterator first, iterator last) |
322 | iterator erase (iterator first, iterator last) |
325 | { |
323 | { |
326 | size_t n = last - first; |
324 | size_type n = last - first; |
|
|
325 | size_type c = end () - last; |
327 | |
326 | |
328 | if (is_simple_enough ()) |
327 | if (is_simple_enough ()) |
329 | memmove (first, last, sizeof (T) * n); |
328 | memmove (first, last, sizeof (T) * c); |
330 | else |
329 | else |
331 | copy<iterator> (first, last, n, cop_new); |
330 | copy (first, last, c, cop_set); |
332 | |
331 | |
333 | sze -= n; |
332 | sze -= n; |
334 | destruct (buf + sze, n); |
333 | destruct (buf + sze, n); |
335 | } |
|
|
336 | |
334 | |
|
|
335 | return first; |
|
|
336 | } |
|
|
337 | |
337 | void erase (iterator pos) |
338 | iterator erase (iterator pos) |
338 | { |
339 | { |
339 | if (pos != end ()) |
340 | if (pos != end ()) |
340 | erase (pos, pos + 1); |
341 | erase (pos, pos + 1); |
|
|
342 | |
|
|
343 | return pos; |
341 | } |
344 | } |
342 | }; |
345 | }; |
343 | |
346 | |
344 | template<class T> |
347 | template<class T> |
345 | bool operator ==(const simplevec<T> &v1, const simplevec<T> &v2) |
348 | bool operator ==(const simplevec<T> &v1, const simplevec<T> &v2) |