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
Comment #2 by github-bugzilla — 2014-04-23T13:35:05Z
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.