Skip to content

Instantly share code, notes, and snippets.

@adrian17 adrian17/main.cpp
Created Jul 25, 2016

Embed
What would you like to do?
concepts diagn
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
You can’t perform that action at this time.