ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/src/estl.h
(Generate patch)

Comparing libptytty/src/estl.h (file contents):
Revision 1.19 by sf-exg, Thu May 24 11:48:18 2012 UTC vs.
Revision 1.27 by sf-exg, Fri Nov 7 20:44:49 2014 UTC

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
38template<class T> 38template<class T>
39struct simplevec 39struct 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_constructible<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) || ECB_CLANG_VERSION(2,8)
74 return __has_trivial_assign (T) 74 return __has_trivial_assign (T)
75 && __has_trivial_constructor (T) 75 && __has_trivial_constructor (T)
76 && __has_trivial_copy (T) 76 && __has_trivial_copy (T)
77 && __has_trivial_destructor (T); 77 && __has_trivial_destructor (T);
78 #else 78 #else
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
160public: 160public:
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);
320 return buf + at; 319 return buf + at;
321 } 320 }
322 321
323 iterator 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 334
335 return first; 335 return first;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines