Skip to content

Instantly share code, notes, and snippets.

@doubleday
Created July 24, 2015 18:15
Show Gist options
  • Save doubleday/eeaec462a2274c864183 to your computer and use it in GitHub Desktop.
Save doubleday/eeaec462a2274c864183 to your computer and use it in GitHub Desktop.
Create compile time int lookup table
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