Created
October 18, 2017 00:43
-
-
Save benloong/c6dcda0e7f9076d483fea0e451e7f936 to your computer and use it in GitHub Desktop.
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<unsigned... Is> struct seq{}; | |
template<unsigned N, unsigned... Is> | |
struct gen_seq : gen_seq<N-1, N-1, Is...>{}; | |
template<unsigned... Is> | |
struct gen_seq<0, Is...> : seq<Is...>{}; | |
enum Type { | |
Alphabet, | |
Number, | |
Symbol, | |
Other, | |
}; | |
struct Table { | |
Type _[128]; | |
}; | |
constexpr Type whichCategory(char c){ return (c > 63)? Alphabet : Other; /*lazy*/ } | |
template<unsigned... Is> | |
constexpr Table MagicFunction(seq<Is...>){ | |
return {{ whichCategory(Is)... }}; | |
} | |
constexpr Table MagicFunction(){ | |
return MagicFunction(gen_seq<128>{}); | |
} | |
#include <iostream> | |
int main(){ | |
constexpr Table table = MagicFunction(); | |
for(auto e : table._){ | |
std::cout << e; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment