DIP44: scope(class) and scope(struct)

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Aug 23 17:44:16 PDT 2013


I've written up a proposal to solve the partially-constructed object
problem[*] in D in a very nice way by extending scope guards:

	http://wiki.dlang.org/DIP44

[*] The partially-constructed object problem is when you have a class
(or struct) that must acquire some number of external resources, usually
to set them as member fields, but before the ctor is able to initialize
all of these fields, an Exception is thrown. Now the object is in a
partially-constructed state: some member fields have been initialized,
and need to be destructed in order to release the associated external
resources, but other fields are still uninitialized so should not be
destructed. This leads to the problem of, how do we clean up in this
situation? We can't call the dtor -- the dtor assumes *all* fields have
been set and will wrongly try to release resources that haven't been
acquired yet. But we can't ignore the issue either -- the resources that
*have* been required need to be released somehow. This DIP proposes a
nice solution to this problem that fits in very well with the existing
scope guards in D.

Destroy! ;-)


T

-- 
Only boring people get bored. -- JM


More information about the Digitalmars-d mailing list