Last active
February 16, 2019 09:38
-
-
Save charlesxsh/e5df961786dd432fad26957a3239d93b to your computer and use it in GitHub Desktop.
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
template <bool, typename T = void> | |
struct stop_if{ | |
typedef T type; | |
}; | |
template <typename T> | |
struct stop_if<true, T> {}; | |
struct Dog {}; | |
struct Husky : public Dog {}; | |
struct Poodle :public Dog {}; | |
template<class T> | |
struct is_husky { | |
static constexpr bool result = false; | |
}; | |
template<> | |
struct is_husky<Husky> { | |
static constexpr bool result = true; | |
}; | |
template<class T, class = typename stop_if<is_husky<T>::result, T>::type > | |
void DogCanBeSmartExceptHusky(const T&& dog) {}; | |
int main() | |
{ | |
DogCanBeSmartExceptHusky(Poodle{}); | |
DogCanBeSmartExceptHusky(Husky{}); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment