<div dir="ltr">I feel like it would be much better to do this with type deduction, than to introduce new keywords and concepts...<div style>Saying type deduction is hard is probably not accurate. It's either possible, or impossible. If it's mechanically possible, then it's easy for the compiler to do. If it's impossible (or ambiguous), then an error would be thrown in those cases. I'm sure the compiler is capable of working out if it's impossible and complaining.<br>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 6 July 2013 23:50, TommiT <span dir="ltr"><<a href="mailto:tommitissari@hotmail.com" target="_blank">tommitissari@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Saturday, 6 July 2013 at 13:30:02 UTC, TommiT wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Some more details of this proposed feature:<br>
<br>
inout(T) foo(inout T)(T a, T b)<br>
{<br>
    return var;<br>
}<br>
<br>
void bar(inout T)(T a, T b)<br>
{<br>
    a = b;<br>
}<br>
<br>
void main()<br>
{<br>
    const int con;<br>
    immutable int imm;<br>
<br>
    foo(con, con); // OK (returns const int)<br>
    foo(con, imm); // Error: returned inout(T) is ambiguous<br>
<br>
    bar(con, con); // OK<br>
    bar(con, imm); // OK (no ambiguity because inout not used)<br>
}<br>
</blockquote>
<br></div>
Another approach, if we wanted a different syntax, would be to add a new keyword 'mutable'. Like immutable overrides const, mutable would override both const and immutable:<br>
<br>
static assert(is(mutable(const(int)) == int));<br>
static assert(is(mutable(immutable(<u></u>int)) == int));<br>
<br>
Here's how it would look:<br>
<br>
T foo(T)(mutable(T) a, mutable(T) b)<br>
{<br>
    a = b = 123;<br>
    return a;<div class="im"><br>
}<br>
<br>
void main()<br>
{<br>
    const int con;<br>
    immutable int imm;<br>
<br>
    foo(con, con); // OK (returns const int)<br></div>
    foo(con, imm); // Error: T is ambiguous<br>
}<br>
</blockquote></div><br></div>