blob: 53f420bd2937a6784c823fa0f6595e65107666f2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#pragma once
#include "MixedArray.hpp"
template <class T, class U>
class DirectConcat : public MixedArray<T, U> {
public:
virtual MixedArray<T, U>* operator+=(const MixedArray<T, U>* other) override;
};
template <class T, class U>
MixedArray<T, U>* DirectConcat<T, U>::operator+=(const MixedArray<T, U>* other) {
T* biggerFirst = new T[this->allocated + other->allocated];
U* biggerSecond = new U[this->allocated + other->allocated];
for (int i = 0; i < this->size; i++) {
biggerFirst[i] = this->first[i];
biggerSecond[i] = this->second[i];
}
for (int i = 0; i < other->size; i++) {
biggerFirst[this->size + i] = other->first[i];
biggerSecond[this->size + i] = other->second[i];
}
delete[] this->first;
this->first = biggerFirst;
delete[] this->second;
this->second = biggerSecond;
this->allocated += other->allocated;
this->size += other->size;
return this;
}
|