From 29f65b266adfc2d4309a77d60381a285857d7b19 Mon Sep 17 00:00:00 2001 From: Denis Shelomovskij Date: Tue, 6 Nov 2012 13:16:43 +0400 Subject: [PATCH] Add `std.conv.destruct` function --- std/conv.d | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/std/conv.d b/std/conv.d index 4a194962fb2..2b08dd3fa3a 100644 --- a/std/conv.d +++ b/std/conv.d @@ -3642,6 +3642,22 @@ unittest assert(i is k); } + +/** Destructs a given object $(D t). + +It puts destructed object in its $(D init) state if $(D resetInitialState) +is $(D true), otherwise object state will be undefined (i.e. possibly invalid). + +Note, that it destructs a given object, but not something it references. +So to destruct a class instance, use $(D object.finalizeClassInstance). +*/ +void destruct(T)(ref T t, bool resetInitialState = true) +{ + callDestructors(t); + if(resetInitialState) + setInitialState(t); +} + // Undocumented for the time being void toTextRange(T, W)(T value, W writer) if (isIntegral!T && isOutputRange!(W, char))