48 static inline int imax (
int x,
int y) {
int mask = (y-x) >> (
sizeof(
int)*8-1);
return (x&mask) + (y&(~mask)); }
60 operator T* (void) {
return data; }
64 void shrink (
int nelems) { assert(nelems <=
sz);
for (
int i = 0; i < nelems; i++)
sz--,
data[
sz].~T(); }
65 void shrink_ (
int nelems) { assert(nelems <=
sz);
sz -= nelems; }
70 void clear (
bool dealloc =
false);
97 if (cap >= min_cap)
return;
98 int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1);
99 if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) *
sizeof(T))) ==
nullptr) && errno == ENOMEM))
106 if (sz >= size)
return;
108 for (
int i = sz; i < size; i++) data[i] = pad;
114 if (sz >= size)
return;
116 for (
int i = sz; i < size; i++)
new (&data[i]) T;
122 if (data !=
nullptr){
123 for (
int i = 0; i < sz; i++) data[i].~T();
125 if (dealloc) free(data), data =
nullptr, cap = 0;