D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6793 - Document that assumeUnique may not be necessary in some contexts
Summary: Document that assumeUnique may not be necessary in some contexts
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: Andrej Mitrovic
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2011-10-08 13:31 UTC by bearophile_hugs
Modified: 2014-04-23 13:35 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-10-08 13:31:55 UTC
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 2 github-bugzilla 2014-04-23 13:35:05 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/20d91e6f3ff955601f9ab6e41f483771e1880f68
Fix Issue 6793 - Document that assumeUnique may not be necessary in some contexts.

https://github.com/D-Programming-Language/phobos/commit/3accfde6c8f5bb458aca9af21bf2c05177c30724
Merge pull request #2109 from AndrejMitrovic/Fix6793

Issue 6793 - Document that assumeUnique may not be necessary in some contexts.