Created
July 28, 2017 09:04
-
-
Save odeblic/ebd33b9f9e6f362d730305d33fb8cc86 to your computer and use it in GitHub Desktop.
SFINAE in practice
This file contains hidden or 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 <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