| |
| Posted by Eldar Insafutdinov in reply to Walter Bright | PermalinkReply |
|
Eldar Insafutdinov
Posted in reply to Walter Bright
| Walter Bright Wrote:
> Eldar Insafutdinov wrote:
> > Walter Bright Wrote:
> >
> >> Max Samukha wrote:
> >>> Here is a non-template implementation that should fix the problems (it is a template but only formally):
> >> Thanks, I've incorporated it.
> >
> > Thanks for that, but what about the other issues, why does this function have to be a template?
>
> So it works with other types, though that isn't implemented.
This code:
-------
void clear(Dummy = void)(Object obj)
{
pragma(msg, "template instance: Object clear");
}
void clear(T)(ref T obj) if (!is(T == class))
{
pragma(msg, "template instance: " ~ T.stringof ~ " clear");
}
class Boo {}
class Foo {}
struct Bar {}
struct Baz {}
void main()
{
auto boo = new Boo;
auto foo = new Foo;
Bar bar;
Baz baz;
clear(boo);
clear(foo);
clear(bar);
clear(baz);
}
-------
outputs during compilation:
template instance: Object clear
template instance: Bar clear
template instance: Baz clear
Isn't that what you need?
>
> > Why does calling __dtor doesn't call base class destructors(as it is done in C++)?
>
> Doing it that way is non-trivial, and I was in a hurry to get the system working. Class destructors are rarely used in D, so doing it the simple way is not a performance issue.
>
> Destructors for structs, however, are done the more complicated (and more performant) way because they need to be more efficient.
>
Thanks for the clarification. This is something I know little about, so I can't argue here.
|