I feel like it would be much better to do this with type deduction, than to introduce new keywords and concepts...
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.


On 6 July 2013 23:50, TommiT <tommitissari@hotmail.com> wrote:
On Saturday, 6 July 2013 at 13:30:02 UTC, TommiT wrote:
Some more details of this proposed feature:

inout(T) foo(inout T)(T a, T b)
{
    return var;
}

void bar(inout T)(T a, T b)
{
    a = b;
}

void main()
{
    const int con;
    immutable int imm;

    foo(con, con); // OK (returns const int)
    foo(con, imm); // Error: returned inout(T) is ambiguous

    bar(con, con); // OK
    bar(con, imm); // OK (no ambiguity because inout not used)
}

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:

static assert(is(mutable(const(int)) == int));
static assert(is(mutable(immutable(int)) == int));

Here's how it would look:

T foo(T)(mutable(T) a, mutable(T) b)
{
    a = b = 123;
    return a;

}

void main()
{
    const int con;
    immutable int imm;

    foo(con, con); // OK (returns const int)
    foo(con, imm); // Error: T is ambiguous
}