On Saturday, 6 July 2013 at 13:30:02 UTC, TommiT wrote: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:
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)
}
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;foo(con, imm); // Error: T is ambiguous
}
void main()
{
const int con;
immutable int imm;
foo(con, con); // OK (returns const int)
}