Here's a question for the c <template> wizards! I would like to modify my

Here’s a question for the c wizards!
I would like to modify my cLEDMatrix class library to allow a matrix type declaration in its constructor that would change the compiled internal mXY() function dependent on matrix type?
Something like:-

CRGB leds[NUM_LEDS];
cLEDMatrix MyMatrix<H_ZIGZAG>(16, 16, leds);

Then in the cLEDMatrix class I would want to change the internal inline mXY(int16_t x, int16_t y) function to have the calculation code for the appropriate type of matrix e.g.
For H_ZIGZAG
if (y % 2)
return((((y + 1) * m_Width) - 1) - x);
else
return((y * m_Width) + x);
or V_ZIGZAG
if (x % 2)
return((((x + 1) * m_Height) - 1) - y);
else
return((x * m_Height) + y);

It would be nice not to have to include several ‘if’ conditions in a frequently called function, especially as the matrix type is fixed at compiler time.
#ifdef would work great if the code was not in a library.

I hope my question makes sense :slight_smile:

Well nobody seemed able to help so I have been battling on…
I now have a Matrix template class that copes with horizontal/vertical/zigzag/alternative origins :slight_smile:
The example code when compiled is over 700 bytes smaller and the section that draws the diagonal stripes is over 8% faster in all cases.
However, I now have the problem that I cannot work out how to setup a pointer to the XY function in my cTextScroller class!