Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions cpptod.dd
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,13 @@ $(H4 The D Way)
and locks, handled automatically with D's $(D synchronized)
declarations and statements.)

$(P The few RAII issues left are handled by $(I scope) classes.
Scope classes get their destructors run when they go out of scope.)
$(P The few RAII issues left are handled by $(D struct)s.
A $(D struct) gets its destructor run when it goes out of scope.)

------
scope class File
{ Handle h;
struct File
{
Handle h;

~this()
{
Expand All @@ -447,13 +448,24 @@ scope class File
void test()
{
if (...)
{ scope f = new File();
{
auto f = File();
...
} // f.~this() gets run at closing brace, even if
// scope was exited via a thrown exception
}
------

$(P $(D class)es are typically managed by the garbage collector which doesn't
lend itself to RAII. If you need deterministic destruction with $(D class)es
you can use $(FULL_XREF typecons, scoped) (which will also allocate the
$(D class) on the stack instead of the garbage collector managed heap).)

$(P See also $(GLINK2 statement, ScopeGuardStatement) for a more generalized
mechanism that lets you run arbitrary statements whenever leaving the current
scope.)


<hr><!-- -------------------------------------------- -->
$(H3 <a name="properties">Properties</a>)

Expand Down