Created
July 24, 2015 18:15
-
-
Save doubleday/eeaec462a2274c864183 to your computer and use it in GitHub Desktop.
Create compile time int lookup table
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
template <int Val> | |
struct int_const : std::integral_constant<int, Val> {}; | |
template <typename In, typename T> | |
struct getMappedOutput; | |
template <typename In, typename Left, typename Right, typename ...Tail> | |
struct getMappedOutput<In, std::tuple<Left, Right, Tail...>> | |
: getMappedOutput<In, std::tuple<Tail...>> | |
{ | |
}; | |
template <typename In, typename Right, typename ...Tail> | |
struct getMappedOutput<In, std::tuple<In, Right, Tail...>> | |
{ | |
static constexpr auto value = Right::value; | |
}; | |
int main() | |
{ | |
using lookup = std::tuple<int_const<0>, int_const<1>, int_const<1>, int_const<0>>; | |
auto result = getMappedOutput<int_const<0>, lookup>::value; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment