enum pointers or class references limitation

Dmitry Olshansky via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 30 02:36:43 PDT 2017


The subj is not (any longer) supported by compiler. In fact it 
used to produce wrong code sometimes and now it just plainly 
rejects it.

It's freaking inconvenient because I can't deploy new 
compile-time std.regex w/o it.

The example:

enum ctr = ctRegex!"blah";

after my changes must be:

static immutable ctr = ctRegex!"blah";

Howeever I divised a trick to get equivalent functionality as 
follows:

template ctRegexImpl(alias pattern, string flags=[])
{
    static immutable staticRe = ...;
    struct Wrapper
    {
       @property auto getRe(){ return staticRe; }
       alias getRe this;
    }
    enum wrapper = Wrapper();
}

public enum ctRegex(alias pattern, alias flags=[]) = 
ctRegexImpl!(pattern, flags).wrapper;

Now ctRegex returns a neat forwarding struct that bypasses the 
strange limitation. The question remains though - why can't 
compiler do it automatically?



More information about the Digitalmars-d mailing list