Vector design notes

Back to Vectors

What concept should the Type model?

Vectors in

First of all, we abuse terminology here. By vectors in we actually mean elements of a module over . If the scalars are , then we have module elements, if the scalars are , then we have vectors. We don’t want to implement Vectors separately for the modules because they would be identical to the Vector implementation. Thus we embed them into the existing Vector class. We need to separate those functions that only require the scalar set to be an ordered ring and those that require the scalar set to be . Note the use of an ordered ring rather to underline that the functions should work for too.

Rejected ideas

Vector is-a Tuple

It should be possible to pass a vector to a function requiring a tuple:

template <typename Type, integer N>
void f(const Tuple<N, Type>& left)
{
    //...
}

Vector<float> a;
f(a);

It is essential that the Tuple be a base-class of Vector to make the template parameter deduction to work. However, the use of expression templates also requires that a VectorExpression is a base class of Vector.

If we now use the obvious multiple inheritance to achieve this hierarchy, then we increase the memory cost by 4 bytes which is unacceptable for static Vectors.

Could we convert the inheritance hierarchy to a linear one? Clearly the Tuple can’t be a base-class of the VectorExpression because then every sub-expression would take the Tuple’s amount of extra memory (which most of the time is not used at all). So the question is if we should make the VectorExpression a base-class of the Tuple? The answer is no because that would not make sense when then Tuple is used on its own.

Thus it seems this requirement can’t be satisfied.