Beef
Beef copied to clipboard
Can not use function for valueless generic constraint
Current
This code does not compile.
namespace test;
class Program
{
static T Max<T, TFunc>(T lhs, T rhs, TFunc func) where TFunc : function int(T lhs, T rhs)
{
return (func(lhs, rhs) >= 0) ? lhs : rhs;
}
static int Cmp(float lhs, float rhs)
{
return lhs <=> rhs;
}
float max = Max(5.4f, 1.2f, => Cmp);
}
Generic argument 'TFunc', declared to be 'method reference test.Program.Cmp(float lhs, float rhs)' for 'test.Program.Max<float, method reference test.Program.Cmp(float lhs, float rhs)>(float lhs, float rhs, method reference test.Program.Cmp(float lhs, float rhs) func)', must derive from 'function int(float lhs, float rhs)'
Expected
This code should compile.