This might be an odd question, but how does one nicely loop over ALL values of a type. In particular the standard integral types such as unsigned short
. A normal for
loop construct presents a difficulty: what condition to use to exit the loop - because all values are valid.
Of course, there are several ways to get the job done. Exit on the last value then handle that after the loop. Use a bigger int to count. The question is, is there a more elegant way?