B
bartek
template <class T, unsigned size>
struct Array {
typedef unsigned SizeType;
typedef T ValueType;
typedef T* Ptr;
typedef T const* ConstPtr;
// Default copy ctor and assignment op are fine.
SizeType Size() const { return size; }
T& operator[](SizeType i) { return m_array; }
T const& operator[](SizeType i) const { return m_array; }
Ptr Begin() { return &m_array[0]; }
ConstPtr Begin() const { return &m_array[0]; }
Ptr End() { return &m_array[0] + size; }
ConstPtr End() const { return &m_array[0] + size; }
private:
ValueType m_array[size];
};
It defines neither a copy-ctor nor a destructor.
Does the presence of private section render it as non-POD?
I assume that, if the above class was a POD type, objects of the
following types T and U would end up with equivalent memory layout:
typedef float TX[3];
typedef TX TY[4];
typedef Array<float, 3> UX;
typedef Array<UX, 4> UY;
typedef TY T;
typedef UY U;
Thanks.
struct Array {
typedef unsigned SizeType;
typedef T ValueType;
typedef T* Ptr;
typedef T const* ConstPtr;
// Default copy ctor and assignment op are fine.
SizeType Size() const { return size; }
T& operator[](SizeType i) { return m_array; }
T const& operator[](SizeType i) const { return m_array; }
Ptr Begin() { return &m_array[0]; }
ConstPtr Begin() const { return &m_array[0]; }
Ptr End() { return &m_array[0] + size; }
ConstPtr End() const { return &m_array[0] + size; }
private:
ValueType m_array[size];
};
It defines neither a copy-ctor nor a destructor.
Does the presence of private section render it as non-POD?
I assume that, if the above class was a POD type, objects of the
following types T and U would end up with equivalent memory layout:
typedef float TX[3];
typedef TX TY[4];
typedef Array<float, 3> UX;
typedef Array<UX, 4> UY;
typedef TY T;
typedef UY U;
Thanks.