Skip to content

Instantly share code, notes, and snippets.

@sthalik
Created July 1, 2022 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sthalik/0828be17146ddad36f4a3e11b47cbbcc to your computer and use it in GitHub Desktop.
Save sthalik/0828be17146ddad36f4a3e11b47cbbcc to your computer and use it in GitHub Desktop.
#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