46 #ifndef AI_SMALLVECTOR_H_INC
47 #define AI_SMALLVECTOR_H_INC
50 # pragma GCC system_header
62 template<
typename T,
unsigned int Capacity>
67 mStorage(mInplaceStorage),
75 if (mStorage != mInplaceStorage) {
83 if (mSize < mCapacity) {
84 mStorage[mSize++] = item;
88 push_back_and_grow(item);
94 if (newSize > mCapacity) {
115 return &mStorage[mSize];
127 return &mStorage[mSize];
136 void grow(
size_t newCapacity) {
137 T* oldStorage = mStorage;
138 T* newStorage =
new T[newCapacity];
140 std::memcpy(newStorage, oldStorage, mSize *
sizeof(T));
142 mStorage = newStorage;
143 mCapacity = newCapacity;
145 if (oldStorage != mInplaceStorage) {
146 delete [] oldStorage;
150 void push_back_and_grow(
const T& item) {
151 grow(mCapacity + Capacity);
153 mStorage[mSize++] = item;
159 T mInplaceStorage[Capacity];
164 #endif // !! AI_SMALLVECTOR_H_INC
T * end() const
Returns a const pointer to the end.
Definition: SmallVector.h:126
void push_back(const T &item)
Will push a new item. The capacity will grow in case of a too small capacity.
Definition: SmallVector.h:82
T * end()
Returns a pointer to the end.
Definition: SmallVector.h:114
void resize(size_t newSize)
Will resize the vector.
Definition: SmallVector.h:93
Small vector with inplace storage.
Definition: SmallVector.h:63
SmallVector()
The default class constructor.
Definition: SmallVector.h:66
T * begin() const
Returns a const pointer to the first item.
Definition: SmallVector.h:120
T * begin()
Returns a pointer to the first item.
Definition: SmallVector.h:108
~SmallVector()
The class destructor.
Definition: SmallVector.h:74
size_t size() const
Returns the current size of the vector.
Definition: SmallVector.h:102
Definition: ai_assert.h:50