<div dir="ltr">2013/11/10 Timon Gehr <span dir="ltr"><<a href="mailto:timon.gehr@gmx.ch" target="_blank">timon.gehr@gmx.ch</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">On 11/10/2013 12:07 PM, Kenji Hara wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
Condider a case that copying "inout struct" inside inout function.<br>
<br>
struct S {<br>
     int[] arr;<br>
     this(this) ??? { }<br>
}<br>
int[] foo(inout S src)<br>
{<br>
     S dst = src; // copy inout S to S<br>
     return dst.arr;<br>
}<br>
<br>
If the struct S has postblit, what shold be done for "copying S from<br>
inout to mutable"?<br>
<br>
1. You cannot modify elements of arr field, because originally it may be<br>
immutable.<br>
2. You must re-initialize arr field by unique expression, otherwise it<br>
may break type system<br></div>
...<br>
</blockquote>
<br>
2. is not necessary in the following case:<br>
<br>
inout(int)[] foo(inout S src){<br>
    inout(S) dst = src; // copy inout S to inout S<br>
    return dst.arr;<br>
}<br>
<br>
But as far as I understand, there is no other postblit than inout to invoke under the current proposal, hence this could be wasteful.<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
The requirements are exactly same as what necessary for unique postblit.<br>
Essentially "creating unique copy" is exactly same as "treating the copy<br>
source as inout".<br>
</blockquote>
<br></div>
I think it is a good design, but maybe still incomplete.<br>
<br>
We could eg. keep<br>
<br>
this(this)inout{ ... }<br>
<br>
as the unique postblit and have<br>
<br>
this(inout this)inout{ ... }<br>
<br>
as a postblit for identically qualified source and target.<br>
</blockquote></div><br></div><div class="gmail_extra">Hmm.</div><div class="gmail_extra">As a side note, I'm planning unique constructor definition.</div><div class="gmail_extra"><br></div><div class="gmail_extra">struct S {</div>
<div class="gmail_extra">    // If constructor has one or more inout parameters, it will become inout constructor<br></div><div class="gmail_extra">    // The constructed object qualifier will be restricted by the argument types.</div>
<div class="gmail_extra">    this(inout int[] arr) inout { ... }</div><div class="gmail_extra"><br></div><div class="gmail_extra">    // If constructor has no inout parameters, it will become unique constructor<br></div><div class="gmail_extra">
    // The constructed object type can have arbitrary qualifier</div><div class="gmail_extra">    this(int[] arr) inout { ... }</div><div class="gmail_extra">}<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">
So, separating "inout postblit' and 'unique postblit' may be reasonable.</div><div class="gmail_extra"><br></div><div class="gmail_extra">(However, it seems to me that the syntax "this(inout this) inout;" looks weird...</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Kenji Hara</div><div class="gmail_extra"><br></div></div>