Answer the question
In order to leave comments, you need to log in
How to create a concept whose functions have type inference?
I am writing the next concept.
template <typename T>
concept bool Condition = requires(T a) {
{ a.match(...) } -> bool;
};
class A {
public:
template <typename T>
bool match(T&& t) {
t == 1;
}
};
Answer the question
In order to leave comments, you need to log in
The concept must be applied to the calling code. I slightly modified your example for the general case. Now they can check if any class contains a match method with a certain signature:
template <class T, class V>
concept bool HasMethodMatch = requires(T a, V v) {
{ a.match(v) } -> bool;
};
class A {
public:
template <class T>
bool match(T t) const {
return t == 1;
}
};
template <class V>
requires HasMethodMatch<A, V>
void doSmth(const A& a, V v)
{
a.match(v);
}
int main()
{
A a;
doSmth(a, 5);
doSmth(a, 5.f);
doSmth(a, 5.d);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question