Created
July 25, 2016 21:26
-
-
Save adrian17/e750d65e7b58f9251be49cca9ba778af to your computer and use it in GitHub Desktop.
concepts diagn
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<typename T> using id=T; | |
template<typename T> | |
concept bool A = requires(T a) { a==a; }; | |
template<typename T, typename U> | |
concept bool B = | |
A<T> && // (1) basic usage | |
A<T> && // (2) duplicate concept check | |
A<U> && // (3) different concept check that happens to work on the same type here | |
A<id<T>>; // (4) same as above | |
template<typename T> requires B<T, T> void f(T){} | |
struct S{} s; // operator== not defined | |
int main(){ f(s); } | |
/* | |
main.cpp: In function ‘int main()’: | |
main.cpp:16:16: error: cannot call function ‘void f(T) [with T = S]’ | |
int main(){ f(s); } | |
^ | |
main.cpp:13:44: note: constraints not satisfied | |
template<typename T> requires B<T, T> void f(T){} | |
^ | |
main.cpp:7:14: note: within ‘template<class T, class U> concept const bool B<T, U> [with T = S; U = S]’ | |
concept bool B = | |
^ | |
main.cpp:4:14: note: within ‘template<class T> concept const bool A<T> [with T = S]’ | |
concept bool A = requires(T a) { a==a; }; | |
^ | |
main.cpp:4:14: note: with ‘S a’ | |
main.cpp:4:14: note: the required expression ‘(a == a)’ would be ill-formed | |
main.cpp:4:14: note: within ‘template<class T> concept const bool A<T> [with T = S]’ | |
main.cpp:4:14: note: with ‘S a’ | |
main.cpp:4:14: note: the required expression ‘(a == a)’ would be ill-formed | |
main.cpp:4:14: note: within ‘template<class T> concept const bool A<T> [with T = S]’ | |
main.cpp:4:14: note: with ‘S a’ | |
main.cpp:4:14: note: the required expression ‘(a == a)’ would be ill-formed | |
main.cpp:4:14: note: within ‘template<class T> concept const bool A<T> [with T = S]’ | |
main.cpp:4:14: note: with ‘S a’ | |
main.cpp:4:14: note: the required expression ‘(a == a)’ would be ill-formed | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment