Concepts: checking signatures of methods with arguments
I've been playing around with concepts. Here's a minimal example where I'm trying to create a concept based on method signatures:
template
concept bool myConcept() {
return requires(T a, int i) {
{ a.foo() } -> int;
{ a.bar(i) } -> int;
};
}
struct Object {
int foo() {return 0;}
int bar(int) {return 0;}
};
static_assert(myConcept(), "Object does not adhere to myConcept");
To my surprise writing { a.bar(int) } -> int did not work, so I resorted to adding an additional argument to the requires expression. This seems a bit strange and I was wondering if there is a way to do the same thing. Another thing that worked was using something like { a.bar((int)0) } -> int, but I find this worse.
0 comments:
Post a Comment
Thanks