[Issue 13909] A problem with immutable zip + assocArray

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jan 2 00:14:10 PST 2015


https://issues.dlang.org/show_bug.cgi?id=13909

bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
           Severity|normal                      |enhancement

--- Comment #2 from bearophile_hugs at eml.cc ---
(In reply to Peter Alexander from comment #1)

> so you are trying to create an associative array with const values
> (not keys), which isn't possible with assocArray.

I see. This code gives:


void main() {
    const(string)[string] aa;
    aa["a"] = "b";
}


test.d(3,7): Error: cannot modify const expression aa["a"]

So I change this issue a little, now it's a diagnostic problem.

Perhaps it's a good idea to add a template constraint to assocArray:


import std.traits: isMutable;

auto assocArray(Range)(Range r)
    if (isInputRange!Range &&
        ElementType!Range.length == 2 &&
        isMutable!(ElementType!Range.Types[1]))
{
...

--


More information about the Digitalmars-d-bugs mailing list