21 #ifndef mia_core_vector_hh
22 #define mia_core_vector_hh
41 struct array_destructor {
43 virtual void operator () (T *p) {
55 struct array_void_destructor {
57 virtual void operator () (T *) {
79 typedef const T& const_reference;
81 typedef const T *const_iterator;
82 typedef size_t size_type;
94 m_data(new T[n], array_destructor<T>()),
98 memset(m_data.get(), 0, m_size*
sizeof(T));
106 m_size(other.m_size),
107 m_data(other.m_data),
108 m_cdata(other.m_cdata)
115 m_size = other.m_size;
116 m_data = other.m_data;
117 m_cdata = other.m_cdata;
129 m_data(init, array_void_destructor<T>()),
153 "Vector::operator[]: No writeable data availabe or not unique,"
154 " call Vector::make_unique() first or enforce the use of "
155 "'Vector::operator[](...) const'");
156 return m_data.get()[i];
172 "Vector::begin(): No writeable data availabe or not unique, "
173 "call Vector::make_unique() first or enforce the use of "
174 "'Vector::begin() const'");
183 "Vector::begin(): No writeable data availabe or not unique, "
184 "call Vector::make_unique() first or enforce the use of "
185 "'Vector::end() const'");
186 return m_data.get() + m_size;
200 const_iterator
end()
const{
201 return m_cdata + m_size;
221 if (m_data && m_data.unique())
226 m_data.reset(
new T[m_size], array_destructor<T>());
227 std::copy(m_cdata, m_cdata + m_size, m_data.get());
228 m_cdata = m_data.get();
233 std::shared_ptr<T> m_data;