| 1 |
// PR c++/82565 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
struct string |
| 5 |
{ |
| 6 |
string(); |
| 7 |
string(const char *); |
| 8 |
bool empty() const; |
| 9 |
}; |
| 10 |
|
| 11 |
template<class From, class To> |
| 12 |
concept convertible_to = requires(From (&f)(), void (&g)(To)) { g(f()); }; |
| 13 |
|
| 14 |
template<typename T, typename ReturnType> |
| 15 |
concept Concept = |
| 16 |
requires(T t, const string& s) { |
| 17 |
{ t(s) } -> convertible_to<ReturnType>; |
| 18 |
}; |
| 19 |
|
| 20 |
struct test { |
| 21 |
string _str; |
| 22 |
|
| 23 |
template<typename Visitor> |
| 24 |
requires Concept<Visitor, bool> |
| 25 |
decltype(auto) visit(Visitor&& visitor) const { |
| 26 |
return visitor(_str); |
| 27 |
} |
| 28 |
|
| 29 |
}; |
| 30 |
|
| 31 |
int main() { |
| 32 |
test().visit([] (auto& x) { return x.empty(); }); |
| 33 |
} |