… | |
… | |
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 | #if __cplusplus >= 201103L |
68 | #if ECB_CPP11 |
69 | return std::is_trivially_assignable<T, T>::value |
69 | return std::is_trivially_assignable<T, T>::value |
70 | && std::is_trivially_constructable<T>::value |
70 | && std::is_trivially_constructable<T>::value |
71 | && std::is_trivially_copyable<T>::value |
71 | && std::is_trivially_copyable<T>::value |
72 | && std::is_trivially_destructible<T>::value; |
72 | && std::is_trivially_destructible<T>::value; |
73 | #elif ECB_GCC_VERSION(4,4) |
73 | #elif ECB_GCC_VERSION(4,4) |
… | |
… | |
145 | buf = nbuf; |
145 | buf = nbuf; |
146 | } |
146 | } |
147 | |
147 | |
148 | construct (buf + sze, n); |
148 | construct (buf + sze, n); |
149 | |
149 | |
150 | sze += n; |
|
|
151 | |
|
|
152 | iterator src = buf + pos; |
150 | iterator src = buf + pos; |
153 | if (is_simple_enough ()) |
151 | if (is_simple_enough ()) |
154 | memmove (src + n, src, sizeof (T) * n); |
152 | memmove (src + n, src, sizeof (T) * (sze - pos)); |
155 | else |
153 | else |
156 | for (size_type i = n; i--; ) |
154 | for (size_type i = sze - pos; i--; ) |
157 | cop_set (src + n + i, src + i); |
155 | cop_set (src + n + i, src + i); |
|
|
156 | |
|
|
157 | sze += n; |
158 | } |
158 | } |
159 | |
159 | |
160 | public: |
160 | public: |
161 | size_type capacity () const { return res; } |
161 | size_type capacity () const { return res; } |
162 | size_type size () const { return sze; } |
162 | size_type size () const { return sze; } |
… | |
… | |
216 | |
216 | |
217 | while (n--) |
217 | while (n--) |
218 | new (buf + n) T (t); |
218 | new (buf + n) T (t); |
219 | } |
219 | } |
220 | |
220 | |
221 | template<class I> |
221 | simplevec (const_iterator first, const_iterator last) |
222 | simplevec (I first, I last) |
|
|
223 | { |
222 | { |
224 | sze = res = last - first; |
223 | sze = res = last - first; |
225 | buf = alloc (sze); |
224 | buf = alloc (sze); |
226 | copy (buf, first, sze, cop_new); |
225 | copy (buf, first, sze, cop_new); |
227 | } |
226 | } |
… | |
… | |
267 | reference operator [](size_type idx) { return buf[idx]; } |
266 | reference operator [](size_type idx) { return buf[idx]; } |
268 | |
267 | |
269 | const_reference at (size_type idx) const { return buf [idx]; } |
268 | const_reference at (size_type idx) const { return buf [idx]; } |
270 | reference at (size_type idx) { return buf [idx]; } |
269 | reference at (size_type idx) { return buf [idx]; } |
271 | |
270 | |
272 | template<class I> |
271 | void assign (const_iterator first, const_iterator last) |
273 | void assign (I first, I last) |
|
|
274 | { |
272 | { |
275 | swap (simplevec<T> (first, last)); |
273 | simplevec<T> v (first, last); |
|
|
274 | swap (v); |
276 | } |
275 | } |
277 | |
276 | |
278 | void assign (size_type n, const T &t) |
277 | void assign (size_type n, const T &t) |
279 | { |
278 | { |
280 | swap (simplevec<T> (n, t)); |
279 | simplevec<T> v (n, t); |
|
|
280 | swap (v); |
281 | } |
281 | } |
282 | |
282 | |
283 | simplevec<T> &operator= (const simplevec<T> &v) |
283 | simplevec<T> &operator= (const simplevec<T> &v) |
284 | { |
284 | { |
285 | assign (v.begin (), v.end ()); |
285 | assign (v.begin (), v.end ()); |
… | |
… | |
294 | buf [at] = t; |
294 | buf [at] = t; |
295 | |
295 | |
296 | return buf + at; |
296 | return buf + at; |
297 | } |
297 | } |
298 | |
298 | |
299 | template<class I> |
|
|
300 | iterator insert (iterator pos, I first, I last) |
299 | iterator insert (iterator pos, const_iterator first, const_iterator last) |
301 | { |
300 | { |
302 | size_type n = last - first; |
301 | size_type n = last - first; |
303 | size_type at = pos - begin (); |
302 | size_type at = pos - begin (); |
304 | |
303 | |
305 | ins (pos, n); |
304 | ins (pos, n); |
… | |
… | |
318 | *i++ = t; |
317 | *i++ = t; |
319 | |
318 | |
320 | return buf + at; |
319 | return buf + at; |
321 | } |
320 | } |
322 | |
321 | |
323 | void erase (iterator first, iterator last) |
322 | iterator erase (iterator first, iterator last) |
324 | { |
323 | { |
325 | size_t n = last - first; |
324 | size_type n = last - first; |
|
|
325 | size_type c = end () - last; |
326 | |
326 | |
327 | if (is_simple_enough ()) |
327 | if (is_simple_enough ()) |
328 | memmove (first, last, sizeof (T) * n); |
328 | memmove (first, last, sizeof (T) * c); |
329 | else |
329 | else |
330 | copy<iterator> (first, last, n, cop_set); |
330 | copy (first, last, c, cop_set); |
331 | |
331 | |
332 | sze -= n; |
332 | sze -= n; |
333 | destruct (buf + sze, n); |
333 | destruct (buf + sze, n); |
334 | } |
|
|
335 | |
334 | |
|
|
335 | return first; |
|
|
336 | } |
|
|
337 | |
336 | void erase (iterator pos) |
338 | iterator erase (iterator pos) |
337 | { |
339 | { |
338 | if (pos != end ()) |
340 | if (pos != end ()) |
339 | erase (pos, pos + 1); |
341 | erase (pos, pos + 1); |
|
|
342 | |
|
|
343 | return pos; |
340 | } |
344 | } |
341 | }; |
345 | }; |
342 | |
346 | |
343 | template<class T> |
347 | template<class T> |
344 | bool operator ==(const simplevec<T> &v1, const simplevec<T> &v2) |
348 | bool operator ==(const simplevec<T> &v1, const simplevec<T> &v2) |