Add Cartesian product iteration. Fixes #1917