I'm using a template class mp_image which has a template argument that specifies the number of channels in the image. "Normal" image has 3 channels, either RGB, Lab, HSL, HSV or any other. A gray scale image has one channel.
Now, for a simple example, I have a member function called SetColor which takes a color (a pointer to an array containing one value for each channel), and puts that color to the whole picture. Currently, I have an iterator i going through each layer one at a time. But if the number of channels would have been known when I wrote the code, I would simply have implemented the code that many times, one time for each channel, without making a loop. Is there some way to perform this (maybe using some template trick) when the number of channels isn't known at the time of coding but at the time of compiling?