Missing in action: generic free functions.
Missing in action: generic free functions.
Why oh why can't I have such nice things in Delphi?
One thing I miss from C++ is dynamic_cast. This is easily implementable in Delphi using generics, but I can't make it a free function, and instead have to use some fugly syntax...
:(
Why oh why can't I have such nice things in Delphi?
One thing I miss from C++ is dynamic_cast
:(
Currently, Generics is tied to classes - not sure why.
ReplyDeleteI know, and frankly it sucks ass. It leads to butt-ugly code, not helped by the poor type deduction. I mean TArray.Sort(myints)... barf
ReplyDeleteThat should read Sort(myints).
I guess it relates to the primitive types in Delphi not sharing a common "root" - but yeah - that could be hidden by the compiler.
ReplyDeleteAsbjørn Heid Just that is a case where I don't agree. I fear you have to prefix most of those Sort calls with the unit name to identify it.
ReplyDeleteUwe Raabe Stop looking at the tree ;)
ReplyDeleteAnother example: In C++ you have dynamic_cast() function. I can't make a nice version of this in Delphi. Best I can do is
y := Dynamic.Cast(x);
Which, while not as horrible as TArray.Sort<> isn't exactly lovely, as it abuses a keyword.
Lars Fosdal I don't buy it. Generic free functions are just overload sugar, sweet sweet sugar.
ReplyDelete