R-Type
R-Type project
Array.hpp
1 #pragma once
2 
3 #include <algorithm>
4 
5 namespace KapMirror {
6  class Array {
7  public:
14  template <typename T>
15  static void resizeArray(T*& array, int size, int newSize) {
16  T* newArray = new T[newSize];
17 
18  std::copy(array, array + std::min(size, newSize), newArray);
19  if (size < newSize) {
20  std::fill(newArray + size, newArray + newSize, 0);
21  }
22  delete[] array;
23  array = newArray;
24  }
25 
32  template <typename T>
33  static T* copyArray(T* array, int size) {
34  T* newArray = new T[size];
35  std::copy(array, array + size, newArray);
36  return newArray;
37  }
38  };
39 } // namespace KapMirror
KapMirror::Array
Definition: Array.hpp:6
KapMirror::Array::resizeArray
static void resizeArray(T *&array, int size, int newSize)
Resize an array.
Definition: Array.hpp:15
KapMirror::Array::copyArray
static T * copyArray(T *array, int size)
Copy an array.
Definition: Array.hpp:33