Reputation: 2428
The following code does not compile:
struct FooImpl {
using Bar = int;
void method(Bar&) {}
};
template <typename F>
concept Foo = requires(F f) {
{ f.method(typename F::Bar{}) };
};
static_assert(Foo<FooImpl>);
The problem comes from the &
in the FooImple::method()
declaration. Removing the &
fixes the problem.
Instead of changing FooImpl
, I would like to change Foo
. How can I change the concept implementation to satisfy the static_assert
?
Upvotes: 0
Views: 374
Reputation: 303537
If the purpose of the concept is to see if F
has a member function named method
that can accept an lvalue of type F::Bar
, then what you want to write is:
template <typename F>
concept Foo = requires (F f, typename F::Bar arg) {
f.method(arg);
};
This will gracefully fail if there is no typename F::Bar
also (i.e. Foo<int>
is false
, not ill-formed).
Upvotes: 2