| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
// { dg-options "-fconcepts" } |
| 3 |
// { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } |
| 4 |
|
| 5 |
#include <cassert> |
| 6 |
|
| 7 |
template<typename T> |
| 8 |
concept Class = __is_class(T); |
| 9 |
|
| 10 |
template<typename T> |
| 11 |
concept Empty = Class<T> and __is_empty(T); |
| 12 |
|
| 13 |
template<Class T> int f(T) { return 1; } |
| 14 |
template<Empty T> int f(T) { return 2; } |
| 15 |
|
| 16 |
struct S { |
| 17 |
template<Class T> int f(T) { return 1; } |
| 18 |
template<Empty T> int f(T) { return 2; } |
| 19 |
} s; |
| 20 |
|
| 21 |
struct X { } x; |
| 22 |
struct Y { X x; } y; |
| 23 |
|
| 24 |
int main () { |
| 25 |
auto p1 = &f<X>; // Empty f |
| 26 |
assert(p1(x) == 2); |
| 27 |
|
| 28 |
auto p2 = &f<Y>; // Class f |
| 29 |
assert(p2(y) == 1); |
| 30 |
|
| 31 |
auto p3 = &S::template f<X>; // Empty f |
| 32 |
assert((s.*p3)(x) == 2); |
| 33 |
|
| 34 |
auto p4 = &S::template f<Y>; // Empty f |
| 35 |
assert((s.*p4)(y) == 1); |
| 36 |
} |