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

[email protected] changed:

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

--- Comment #2 from [email protected] ---
(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]))
{
...

--

Reply via email to