On Monday, 31 October 2016 at 04:35:35 UTC, WhatMeWorry wrote:
I am fascinated with D's module static this.
I have shamelessly stolen Ali's code directly from his book.
module cat;
static this() {
// ... the initial operations of the module ...
}
static ~this() {
// ... the final operations of the module ...
}
First, are there any other languages that has this feature?
The few I know, certainly don't.
Object Pascal has them:
========================
unit foo; // like a D module.
interface
// declarations...,
// like the content of a C/C++ *.h/*.hpp
implementation
// implementation like the content of a C/C++ *.c/*.cpp
initialization
// statements...
// like in a D static this(){}
finalization
// statements...
// like in a D static ~this(){}
end.
========================
Actually without them a lot of stuffs wouldn't work properly.
They are more used than their D equivalent, particularly to
register classes for the object streaming system but not only.