48 static inline int imax (
int x,
int y) {
int mask = (y-x) >> (
sizeof(
int)*8-1);
return (x&mask) + (y&(~mask)); }
50 static inline void nextCap(
int&
cap){ cap += ((cap >> 1) + 2) & ~1; }
60 operator T* (void) {
return data; }
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))) == NULL) && 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();
123 for (
int i = 0; i < sz; i++) data[i].~T();
125 if (dealloc)
free(data), data = NULL, cap = 0; } }
static void copy(const T &from, T &to)
static int imax(int x, int y)
void copyTo(vec< T > ©) const
const T & operator[](int index) const
vec< T > & operator=(vec< T > &other)
void clear(bool dealloc=false)
void push_(const T &elem)
vec(int size, const T &pad)
void moveTo(vec< T > &dest)
static void nextCap(int &cap)
const T & last(void) const