1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-16 07:14:09 +02:00

Added extern constraints to types

This commit is contained in:
Brian Fiete 2020-08-05 05:34:32 -07:00
parent 7724c6ae64
commit c3bc2bc67c
10 changed files with 121 additions and 38 deletions

View file

@ -176,17 +176,28 @@ namespace Tests
return val + val2;
}
public static T Complex<T, T2>(T val, T2 val2)
where T : operator T + T2
public static T Complex<T, T2, T3>(T val, T2 val2, T3 val3)
where T : operator -T
where T : operator implicit T2
where T : operator T + T2
where int32 : operator T + T3
{
T conv = val2;
T result = val + val2;
result = -result;
int32 iRes = val + val3;
return result;
}
struct StructOp3<T, T2> where float : operator T + T2
{
public float Use(T lhs, T2 rhs)
{
float f = lhs + rhs;
return f;
}
}
[Test]
public static void TestBasics()
{
@ -212,7 +223,7 @@ namespace Tests
float val = Op((int32)100, (int16)23);
Test.Assert(val == 123);
int32 i32res = Complex((int32)100, (int16)23);
int32 i32res = Complex((int32)100, (int16)23, (int8)4);
Test.Assert(i32res == -123);
StructOp<StructA, StructB> sOp;
@ -231,6 +242,10 @@ namespace Tests
Test.Assert(rsc == rsc2);
Test.Assert(rsc !== rsc2);
StructOp3<int16, int32> so3 = .();
float f = so3.Use(1, 2);
Test.Assert(f == 3);
/*let oai = OuterOp<float>.InnerOp<int>.Op(1.0f, 100);
Test.Assert(oai == 101.0f);