[Issue 6930] combined type of immutable(T) and inout(T) should be inout(const(T))
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 10 12:38:44 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6930
--- Comment #7 from Steven Schveighoffer <schveiguy at yahoo.com> 2011-11-10 12:38:04 PST ---
What it does is allow you to return data that is immutable, but is not part of
the input, and still have it be immutable after inout is resolved.
The example given isn't quite compelling, because the data is always being
created (even if hidden behind a secondary function).
However, this is a more solid use case:
immutable(int)[] n = [1,2,3];
inout(const(int))[] foo(inout(int)[] x){
import std.random;
bool condition = cast(bool)uniform(0,2);
return condition ? x : n;
}
Without this, this cannot be an inout function. It's signature would be:
const(int)[] foo(const(int)[] x)
Although this is legal, it loses specificity in the case where an immutable is
passed in.
I'm not saying it's not an enhancement or that the benefit is huge, but it's
definitely an improvement.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list