I saw a question about how to make an array of vectors in C++. The answer was that it's impossible, because C arrays are non-copyable and non-assignable, and vector< vector<T> > or vector< pair<T, T> > were offered as alternatives (the length of the underlying array was 2 in the question). The thread is now closed.
I would like to point out that there is in fact a more suitable solution. vector has unnecessary overhead, and a type like pair or tuple is more generic than necessary, because we know all underlying elements are of the same type. An array is the most suitable data type.
There is in fact a copyable and assignable array type in C++: it's a class template called std::tr1::array . It takes the underlying value type and the array size as template arguments. Some compilers don't ship with std::tr1 support, but this container is easy to implement, and even a bare-bones version that supports only operator[] will be enough to effectively replace C arrays in this situation.
I would like to point out that there is in fact a more suitable solution. vector has unnecessary overhead, and a type like pair or tuple is more generic than necessary, because we know all underlying elements are of the same type. An array is the most suitable data type.
There is in fact a copyable and assignable array type in C++: it's a class template called std::tr1::array . It takes the underlying value type and the array size as template arguments. Some compilers don't ship with std::tr1 support, but this container is easy to implement, and even a bare-bones version that supports only operator[] will be enough to effectively replace C arrays in this situation.