Bug 6793 – Document that assumeUnique may not be necessary in some contexts
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-10-08T13:31:00Z
Last change time
2014-04-23T13:35:06Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2011-10-08T13:31:55Z
In the site documentation of std.exception.assumeUnique there is code like:
string letters()
{
char[] result = new char['z' - 'a' + 1];
foreach (i, ref e; result)
{
e = 'a' + i;
}
return assumeUnique(result);
}
But recent improvements of the D language make assumeUnique useless in this case, this compiles:
string lowercase() pure nothrow {
auto result = new char['z' - 'a' + 1];
foreach (i, ref c; result)
c = cast(char)('a' + i);
return result;
}
void main() {}
On the other hand currently (DMD 2.056head) 'a'+i can't be assigned to a char because the compiler doesn't see that the variable 'i' will never become too much big.
So in the documentation of std.exception.assumeUnique I suggest to explain that some usages (where the function is pure) of assumeUnique are not needed now.
Comment #1 by andrej.mitrovich — 2014-04-23T12:58:20Z