Last active
February 17, 2019 10:58
-
-
Save charlesxsh/9e4f084d9902b75195458f96b38b6ca5 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
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<typename T> | |
concept bool ExceptHusky = !is_husky<T>::result; // If T is husky, this concept returns false | |
template<ExceptHusky T> | |
void DogCanBeSmartExceptHusky(const T&& dog) {}; | |
/* | |
template<class T> requires ExceptHusky<T> | |
void DogCanBeSmartExceptHusky(const T&& dog) {}; | |
also works. This is for multiple require expressions, they can use ||, &, ! such operators to join | |
*/ | |
int main() | |
{ | |
DogCanBeSmartExceptHusky(Poodle{}); | |
DogCanBeSmartExceptHusky(Husky{}); | |
// Error message here: | |
// constraints not satisfied | |
//'!(is_husky<Husky>::result)' evaluated to false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment