// Workshop 9:
// Collection template
// 2021-06-03
// Version: 1.0
// Author: Fardad Soleimanloo
/////////////////////////////////////////////
#ifndef SDDS_COLLECTION_H_
#define SDDS_COLLECTION_H_
namespace sdds {
template
class Collection {
T* m_data = nullptr;
int m_size = 0;
public:
Collection(int size = 0);
Collection(const Collection
Collection
int size()const;
void resize(int newsize);
T& operator[](int index);
Collection
~Collection();
};
template
Collection
if (m_size <= 0) m_size = 0;
if (m_size > 0) m_data = new T[m_size];
}
template
Collection
operator=(CP);
}
template
Collection
if (this != &RO) {
delete[] m_data;
m_data = new T[m_size = RO.m_size];
for (int i = 0; i < m_size; i++) m_data[i] = RO.m_data[i];
}
return *this;
}
template
int Collection
return m_size;
}
template
void Collection
int i;
T* temp = nullptr;
if (newsize < 0) newsize = 0;
if (newsize > 0) {
temp = new T[newsize];
for (i = 0; i < m_size && i < newsize; i++) {
temp[i] = m_data[i];
}
}
delete[] m_data;
m_data = temp;
m_size = newsize;
}
template
T& Collection
if (index >= m_size) resize(index + 1);
return m_data[index];
}
template
Collection
(*this)[size()] = element;
return *this;
}
template
Collection
delete[] m_data;
}
}
#endif // !SDDS_COLLECTION_H_