Commit c44fd562 authored by BRAMAS Berenger's avatar BRAMAS Berenger
Browse files

Add operation to the vector to ensure that object without default constructor can be user with it

parent c503873f
......@@ -145,13 +145,14 @@ public:
}
/** Resize the vector (and change the capacity if needed) */
void resize(const int newSize){
template <typename... Args>
void resize(const int newSize, Args... args){
if(index < newSize){
if(capacity < newSize){
setCapacity(int(newSize*1.5));
}
while(index != newSize){
new((void*)&array[index]) ObjectType();
new((void*)&array[index]) ObjectType(args...);
}
}
else{
......@@ -215,6 +216,19 @@ public:
new((void*)&array[index++]) ObjectType(inValue);
}
/**
* To Create a new object
*/
template <typename... Args>
void pushNew(Args... args){
// if needed, increase the vector
if( index == capacity ){
setCapacity(int((capacity+1) * 1.5));
}
// add the new element
new((void*)&array[index++]) ObjectType(args...);
}
/**
* Add one value multiple time
* @param inValue the new value
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment