Created
July 1, 2022 13:21
-
-
Save sthalik/0828be17146ddad36f4a3e11b47cbbcc 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
#include <type_traits> | |
#include <cstdio> | |
template<unsigned N> | |
struct priority_tag : priority_tag<N-1> {}; | |
template<> struct priority_tag<0> {}; | |
struct sfinae { | |
template<typename t> static std::enable_if_t<sizeof(t) >= 4> op(t, priority_tag<2> = {}) { printf("foo4\n"); } | |
template<typename t> static std::enable_if_t<sizeof(t) >= 2> op(t, priority_tag<1> = {}) { printf("foo2\n"); } | |
template<typename t> static void op(t, priority_tag<0> = {}) { printf("foo1\n"); } | |
}; | |
template<typename t> | |
void op(t x) { sfinae::op(x, priority_tag<2>{}); } | |
int main(void) { | |
op(int{}); | |
op(short{}); | |
op(char{}); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment