C++ Concepts - Can I have a constraint requiring a function be present in a class?
You are testing for presence of a static member function. What you want is
template <typename T>
concept bool HasFunc1 =
requires(T t) {
{ t.func1() } -> int;
};
Try calling it yourself:
Test::func1();
prog.cc: In function 'int main()':
prog.cc:19:14: error: cannot call member function 'int Test::func1()' without object
19 | Test::func1();
| ^
Oh, right. func1
should either be a static
member function, or you should call it on an instance inside your concept:
template <typename T>
concept bool HasFunc1 =
requires(T t) {
{ t.func1() } -> int;
};