Created
March 1, 2012 15:00
-
-
Save JakobOvrum/1950300 to your computer and use it in GitHub Desktop.
Range!() template for static range foreach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template Range(int from, int to) if(from < to) | |
{ | |
alias RangeImpl!(from, to - 1) Range; | |
} | |
template RangeImpl(int lowerLimit, int iterator, tail...) | |
{ | |
static if(iterator < lowerLimit) | |
alias tail RangeImpl; | |
else | |
alias RangeImpl!(lowerLimit, iterator - 1, iterator, tail) RangeImpl; | |
} | |
void main() { | |
foreach(n; Range!(0, 0xFF)) | |
pragma(msg, n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment