Skip to content

Instantly share code, notes, and snippets.

@charlesxsh
Last active February 16, 2019 09:38
Show Gist options
  • Save charlesxsh/e5df961786dd432fad26957a3239d93b to your computer and use it in GitHub Desktop.
Save charlesxsh/e5df961786dd432fad26957a3239d93b to your computer and use it in GitHub Desktop.
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