C++ Cartesian Products
github.com
github.com
You're right, most people hard code the for loops they need. I call that the "intuitive approach". It works and it makes sense I think and performs OK. In fact, whenever I come up with new ways to do CPs I always compare their performance to the hard coded loops.
I've been fascinated by CPs for some time. In particular, efficient ways in which to generate them. So I placed my source code on github that demonstrates a few ways I've done it in the past. My hope is that others can offer suggestions and insight into different (especially faster) approaches to generate them.