Skip to content

Instantly share code, notes, and snippets.

@odeblic
Created July 28, 2017 09:04
Show Gist options
  • Save odeblic/ebd33b9f9e6f362d730305d33fb8cc86 to your computer and use it in GitHub Desktop.
Save odeblic/ebd33b9f9e6f362d730305d33fb8cc86 to your computer and use it in GitHub Desktop.
SFINAE in practice
#include <iostream>
struct Object
{
typedef int type;
static void action()
{
std::cout << "Object::action()" << std::endl;
}
};
template <typename T>
void f(typename T::type)
{
std::cout << "f<T>(T::type)" << std::endl;
}
template <typename T>
void f(T)
{
T::action();
}
template <>
void f<int>(int)
{
std::cout << "f<int>(int)" << std::endl;
}
int main()
{
f(Object());
f<Object>(10);
f<int>(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment