I'm kind of stumped as to how to write this in C++, seeing as I need some way of making the out of range array references = 0.

Source, filter and output arrays:
Code:
S [7] = { 1,2,3,4,5,6,7 };
Filter [3] = { a0,a1,a2 };
out [x];
out[0] = a0.V[0] + a1.V[X]+ a2.V[X]
out[1] = a0.V[1] + a1.V[0] + a2.V[X]
out[2] = a0.V[2] + a1.V[1] + a2.V[0]
out[3] = a0.V[3] + a1.V[2] + a2.V[1]
out[4] = a0.V[4] + a1.V[3] + a2.V[2]
out[5] = a0.V[5] + a1.V[4] + a2.V[3]
out[6] = a0.V[6] + a1.V[5] + a2.V[4]
out[7] = a0.V[X] + a1.V[6] + a2.V[5]
out[8] = a0.V[X] + a1.V[X] + a2.V[6]

The only way I can see to do it would be to include an 'if' statement; e.g. "if (i<0) i=0;", but that seems horribly inefficient.

Has anyone got a better idea?

Any help would be greatly appreciated!