Beeflang - open source performance-oriented compiled programming language
Rumbu
rumbu at rumbu.ro
Thu Jan 9 19:20:07 UTC 2020
I find very interesting the approach used to implement struct
interfaces without any boxing. Very clean and nice.
struct Circle : IDrawable
{ void Draw() {} }
/* Calling the following method with an instance of Circle will
first cause boxing to occur at the
callsite, then Draw will be called via dyanmic dispatch (method
table) */
public static void DrawDynamic(IDrawable val)
{
val.Draw();
}
/* Calling the following method with an instance of Circle will
create a specialized instance of
the DrawGeneric method which accepts a Circle argument and
statically calls the Circle.Draw
method, which is faster */
public static void DrawGeneric<T>(T val) where T : IDrawable
{
val.Draw();
}
More information about the Digitalmars-d
mailing list