Created
August 19, 2020 14:49
-
-
Save KillerGoldFisch/e1d543f62856cb6ab00ec6bf3dd8ae61 to your computer and use it in GitHub Desktop.
This file contains 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
// Example program | |
#include <iostream> | |
#include <string> | |
const char* iterationLabels[] = { | |
"Iteration 0", "Iteration 1", "Iteration 2", "Iteration 3", "Iteration 4", "Iteration 5", "Iteration 6", "Iteration 7", "Iteration 8", "Iteration 9", "Iteration 10", "Iteration 11", "Iteration 12", "Iteration 13", "Iteration 14", "Iteration 15", "Iteration 16", "Iteration 17", "Iteration 18", "Iteration 19", "Iteration ..." | |
}; | |
template<typename T, int N> | |
int ArraySize(T(&)[N]) | |
{ | |
return N; | |
} | |
template<typename T, int N> | |
T& ArrayClamp(T (&s)[N], int i) | |
{ | |
return s[std::max(0, std::min(N-1, i))]; | |
} | |
int main() | |
{ | |
std::cout << ArraySize(iterationLabels) << "!\n"; | |
for(int i = -2; i < 23; i++) { | |
std::cout << ArrayClamp(iterationLabels, i) << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment