Created
June 25, 2016 22:41
-
-
Save ricejasonf/a98c96b8001dcee975e0071858ed6d53 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
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