1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-24 02:28:01 +02:00

Added support for const string generic args

This commit is contained in:
Brian Fiete 2022-02-04 14:26:50 -05:00
parent 361be9dc92
commit a87ccd299d
5 changed files with 63 additions and 5 deletions

View file

@ -433,6 +433,24 @@ namespace Tests
return a;
}
static Type GetMathRetType<T, T2>()
{
return typeof(T);
}
static String GetMathString<T, T2>(String expr)
{
if ((typeof(T) == typeof(float)) && (typeof(T2) == typeof(int)))
return scope $"return a{expr}(T)b;";
else
return "return default;";
}
static comptype(GetMathRetType<T, T2>()) ComputeMath<T, T2, TExpr>(T a, T2 b, TExpr expr) where TExpr : const String
{
Compiler.Mixin(GetMathString<T, T2>(expr));
}
[Test]
public static void TestBasics()
{
@ -506,6 +524,11 @@ namespace Tests
int b = 34;
Test.Assert(GetMixinVal() == 123);
Test.Assert(b == 234);
float math = ComputeMath(2.3f, 2, "*");
Test.Assert(math == 4.6f);
float math2 = ComputeMath<float, int, const "+">(2.3f, 1, "+");
Test.Assert(math2 == 3.3f);
}
}
}