Table lookups - this is pretty definitive

Artur Skawina art.08.09 at gmail.com
Tue Apr 1 13:20:40 PDT 2014


On 04/01/14 21:35, JR wrote:
> On Tuesday, 1 April 2014 at 18:35:50 UTC, Walter Bright wrote:
>> immutable bool[256] tab2;
>> static this()
>> {
>>     for (size_t u = 0; u < 0x100; ++u)
>>     {
>>         tab2[u] = isIdentifierChar0(cast(ubyte)u);
>>     }
>> }
> 
> Table lookups are awesome.
> 
> While tab2 there lends itself to being populated in a static this() it would really lower the bar if we could define static immutable AA literals at compile-time. Or at least CTFE-fill them. Having to rely on static this() for such is unfortunate and hacky.

You mention AAs, so you may already realize this, but there is no
need for a mod ctor in the above example:

   immutable bool[256] tab2 = {
      bool t[256];
      for (size_t u = 0; u < 0x100; ++u)
          t[u] = isIdentifierChar0(cast(ubyte)u);
      return t;
   }();

"Static immutable AAs" can be built at CT likewise, it's just that
their type will be different from "std" RT AAs.

artur


More information about the Digitalmars-d mailing list