Templated iteration using iteration count