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.17 by sf-exg, Sat May 19 13:12:07 2012 UTC vs.
Revision 1.24 by root, Mon Oct 27 14:57:30 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_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
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; }
318 *i++ = t; 318 *i++ = t;
319 319
320 return buf + at; 320 return buf + at;
321 } 321 }
322 322
323 void erase (iterator first, iterator last) 323 iterator erase (iterator first, iterator last)
324 { 324 {
325 size_t n = last - first; 325 size_type n = last - first;
326 size_type c = end () - last;
326 327
327 if (is_simple_enough ()) 328 if (is_simple_enough ())
328 memmove (first, last, sizeof (T) * n); 329 memmove (first, last, sizeof (T) * c);
329 else 330 else
330 copy<iterator> (first, last, n, cop_new); 331 copy (first, last, c, cop_set);
331 332
332 sze -= n; 333 sze -= n;
333 destruct (buf + sze, n); 334 destruct (buf + sze, n);
334 }
335 335
336 return first;
337 }
338
336 void erase (iterator pos) 339 iterator erase (iterator pos)
337 { 340 {
338 if (pos != end ()) 341 if (pos != end ())
339 erase (pos, pos + 1); 342 erase (pos, pos + 1);
343
344 return pos;
340 } 345 }
341}; 346};
342 347
343template<class T> 348template<class T>
344bool operator ==(const simplevec<T> &v1, const simplevec<T> &v2) 349bool operator ==(const simplevec<T> &v1, const simplevec<T> &v2)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines