www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - static immutable AAs documentation

reply =?UTF-8?B?THXDrXM=?= Marques <luis luismarques.eu> writes:
The documentation for AAs gives out this example 
(<https://dlang.org/spec/hash-map.html#static_initialization>):

     immutable long[string] aa = [
       "foo": 5,
       "bar": 10,
       "baz": 2000
     ];

     unittest
     {
         assert(aa["foo"] == 5);
         assert(aa["bar"] == 10);
         assert(aa["baz"] == 2000);
     }

This isn't actually supported:

<https://issues.dlang.org/show_bug.cgi?id=6238>
<https://issues.dlang.org/show_bug.cgi?id=1578>

Given how long this limitation has persisted, wouldn't it be best 
to remove that section from the documentation?
Dec 14 2017
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Friday, December 15, 2017 03:49:53 Luís Marques via Digitalmars-d wrote:
 The documentation for AAs gives out this example
 (<https://dlang.org/spec/hash-map.html#static_initialization>):

      immutable long[string] aa = [
        "foo": 5,
        "bar": 10,
        "baz": 2000
      ];

      unittest
      {
          assert(aa["foo"] == 5);
          assert(aa["bar"] == 10);
          assert(aa["baz"] == 2000);
      }

 This isn't actually supported:

 <https://issues.dlang.org/show_bug.cgi?id=6238>
 <https://issues.dlang.org/show_bug.cgi?id=1578>

 Given how long this limitation has persisted, wouldn't it be best
 to remove that section from the documentation?
It should probably just be changed to used a shared static constructor. e.g. immutable long[string] aa; shared static this() { aa = ["foo": 5, "bar": 10, "baz": 2000]; } since that does work. - Jonathan M Davis
Dec 14 2017