86 #ifndef r_code_vector_h
87 #define r_code_vector_h
90 #include "../submodules/CoreLibrary/CoreLibrary/types.h"
98 #if 0 // If resize causes a crash, then enable this temporary fix which overrides resize but leaks memory.
99 template<
typename T>
class resized_vector {
101 resized_vector() : vector_(new std::vector<T>()) {}
102 resized_vector(
size_t n) : vector_(new std::vector<T>(n)) {}
103 ~resized_vector() {
delete vector_; }
104 size_t size()
const {
return vector_->size(); }
105 T& operator [](
size_t i) {
109 return (*vector_)[i];
111 const T& operator [](
size_t i)
const {
113 return (*vector_)[i];
115 void push_back(T t) { vector_->push_back(t); }
116 void clear() { vector_->clear(); }
117 void resize(
size_t new_size) {
118 if (new_size <= vector_->size()) {
120 vector_->resize(new_size);
124 std::vector<T>* new_vector =
new std::vector<T>(new_size);
125 for (
size_t i = 0; i < vector_->size(); ++i)
126 (*new_vector)[i] = (*vector_)[i];
127 #if 0 // This fails, so comment it out. It's a memory leak, but the code runs.
130 vector_ = new_vector;
132 const std::vector<T>* as_std()
const {
return vector_; }
134 std::vector<T>* vector_;
141 size_t size()
const {
return vector_.size(); }
142 T &operator [](
size_t i) {
145 vector_.resize(i + 1);
148 const T &operator [](
size_t i)
const {
152 void push_back(T t) { vector_.push_back(t); }
153 void clear() { vector_.clear(); }
154 void resize(
size_t new_size) { vector_.resize(new_size); }
155 const std::vector<T>* as_std()
const {
return &vector_; }
157 std::vector<T> vector_;