Skip to content

Instantly share code, notes, and snippets.

@ricejasonf
Created June 25, 2016 22:41
Show Gist options
  • Save ricejasonf/a98c96b8001dcee975e0071858ed6d53 to your computer and use it in GitHub Desktop.
Save ricejasonf/a98c96b8001dcee975e0071858ed6d53 to your computer and use it in GitHub Desktop.
template <int v>
struct int_c { static constexpr int value = v; };
struct a_tag { };
struct b_tag { };
template <bool cond>
struct c_tag
{
static_assert(cond);
};
template <typename T>
constexpr auto get(T)
{
if constexpr(T::value > 9)
return c_tag<false>{};
else if constexpr(T::value > 4)
return b_tag{};
else
return a_tag{};
}
int main()
{
constexpr a_tag a = get(int_c<0>{});
constexpr b_tag b = get(int_c<5>{});
//constexpr c_tag<false> c = get(int_c<10>{});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment