Templates with specialization would be best for this I think. I'm really not an expert on templates, but I think this is one thing templates do pretty well.
Check this out:
http://www.codeproject.com/cpp/crc_meta.asp
--Eric
Unrolling loops