<div dir="ltr">I know at least two cases which T.init is commonly used.<div><br></div><div>1. Inside predicate template for type T.</div><div><br></div><div>template isSomething(T) {</div><div>    enum isSomething = is(typeof({</div>
<div>        //T t1;    // not good if T is nested struct, or has @disable this()</div><div>        //T t2 = void; auto x = t2;  // not good if T is non-mutable type</div><div>        T t = T.init;   // avoid default construct check</div>
<div>        ...use t...</div><div>    }));</div><div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">2. Some library utilities that treats object state directly, e.g. std.conv.emplace<br>
<div class="gmail_quote"><br></div><div class="gmail_quote">Kenji Hara</div><div class="gmail_quote"><br></div><div class="gmail_quote">2013/5/20 Maxim Fomin <span dir="ltr"><<a href="mailto:maxim@maxim-fomin.ru" target="_blank">maxim@maxim-fomin.ru</a>></span><br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
On Monday, 20 May 2013 at 00:55:14 UTC, Kenji Hara wrote:<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Unfortunately this is currently not a bug.<br>
T.init provides "default initialized" object image, and it *does not*<br>
provide "default constructed" object. The difference is important.<br>
<br>
That is already documented in lanugage reference.<br>
<a href="http://dlang.org/property#init" target="_blank">http://dlang.org/property#init</a><br>
<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Note: .init produces a default initialized object, not default<br>
</blockquote>
constructed. That means using .init is sometimes incorrect.<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
1. If T is a nested struct, the context pointer in T.init is null.<br>
2. If T is a struct which has @disable this();, T.init might return a<br>
</blockquote>
logically incorrect object.<br>
<br>
Kenji Hara<br>
<br>
</blockquote>
<br></div>
I think this should be fixed otherwise @disable this() is compromised. What is rationale behind allowing .init?<br>
<br>
</blockquote></div><br></div></div></div>