(P Kenter) wrote in message news:<. com>...
> Dear all.
>
> I'm currently writing unit tests in C++ and am checking 2D or 3D
> 'arrays' for their dimension. These 'arrays' are implemented as
> vectors of vectors. The problem is, the vectors of a vector can differ
> in size if they are initialized incorrectly.
>
Why not make the construction of incorrect 'arrays' impossible using
templates:
template <class T, int dim> class Vec

ublic std::vector<T>{
public:
Vec():std::vector<T>(dim){};
};
template <class T, int dim1,int dim2=dim1> class Array2D

ublic Vec<Vec<T,dim2>,dim1>{
};
and then use them like
main()
{
Array2D<float,5,6> gauss;
Array2D<double,3> square;
gauss[2][3]=2.718;
}
and so on. As written these classes are inefficient if T's default
constructor is expensive since all elements are initialized with their
default values. However, this can be rectified by having more complex
constructors for Vec which pass on their arguments to the std::vector
constructors. As far as I know the standard does not allow default
initializer lists for user defined types, including types defined in
the standard library.