Wow, several different approaches! Thanks everyone, I find this discussion enriching. I find `H. S. Teoh`'s template solution to be the closest to what I need. It adds minimal complexity to the existing implementation.