How would you create a generic buffer or array type template (not using STL) that may be used on a struct type that includes a class or non-trivial type. Something this, which uses memcpy and such which may not be appropriate.
template<class T>
class CGrowableBuffer
{
protected:
T* m_pBuff;
unsigned m_nSize;
unsigned m_nCount;
unsigned m_nGrowBy;
};
// ...
template<class T>
IBOOL CGrowableBuffer<T>::Insert(const T* p, unsigned index, unsigned count)
{
if (index>m_nCount || !SetSize(m_nCount + count))
return FALSE;
memmove(m_pBuff+index+count, m_pBuff+index, (m_nCount-index)*sizeof(T));
if (p==NULL) {
memset(m_pBuff + index, 0, count * sizeof(T));
}
else {
memcpy(m_pBuff + index, p, count * sizeof(T));
}
m_nCount += count;
return TRUE;
}
// ...
std::vectorand copy that. But why are you trying to reinvent the wheel?std::vector? Your future self (and any co-workers) will thank you for it. As for code bloat,std::vectorshould be no more expensive than any replacement you might write for it.