5 ms·
Yes requires is pretty powerful with std::invokable but if one of the parameters of your passed function is also generic then it gets more hairy. template <typ
by injidup 3y ago
Yes requires is pretty powerful with std::invokable but if one of the parameters of your passed function is also generic then it gets more hairy.
template <typename T>
requires std::invokable_r_v<int,int,int>
int foo(T fn){
return fn(10, 20);
}
- gpderetta 3y agoint foo(invocable<int,int> auto fn){ return fn(10,20); } But I think you wanted to show a different example.
- injidup 3y agoI'm on mobile so maybe I mixed the concept and the trait but there should be an invocable_r version that constrains the return type in addition to invocable which just constrains the arguments. And yes the inline version rather than requires is much nicer.
- gpderetta 3y agoOh, I see. Yes, out of the box there is a trait, but not a concept.