Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
heap_array.h
1 #pragma once
2 
3 #include <cstdint>
4 #include <utility>
5 
6 namespace smlt {
7 
8 /*
9  * heap_array<T> is a dynamically allocated array, nothing more, nothing less.
10  * It just ensures that `delete []` is called correctly.
11  */
12 
13 template<typename T>
14 class heap_array {
15 public:
16  heap_array(const std::size_t size):
17  array_(new T[size]),
18  size_(size) {
19  }
20 
21  ~heap_array() {
22  delete [] array_;
23  }
24 
25  std::size_t size() const {
26  return size_;
27  }
28 
29  T& operator[](std::size_t idx) {
30  return array_[idx];
31  }
32 
33  const T& operator[](std::size_t idx) const {
34  return array_[idx];
35  }
36 
37 private:
38  T* array_ = nullptr;
39  const std::size_t size_;
40 };
41 
42 }
smlt
Definition: animation.cpp:25
smlt::heap_array
Definition: heap_array.h:14