www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23174] New: Can't alias tuple when it's part of dot


          Issue ID: 23174
           Summary: Can't alias tuple when it's part of dot expression
                    following a struct literal
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: boris2.9 gmail.com

Reported on the forum by Jacob Carlborg in 2016

https://forum.dlang.org/post/nro8lv$22a3$1 digitalmars.com

import std.meta;

struct Fields(T)
    private static alias toField(alias e) = Field!(__traits(identifier, e));
    alias fields = staticMap!(toField, T.tupleof);

    static alias map(alias F) = staticMap!(F, fields);
    static alias filter(alias pred) = Filter!(pred, fields);

struct Field(string n)
    enum name = n;

struct Foo
    int a;

void main()
    Foo value;

    enum toName(alias e) = e.name;
    enum pred(alias e) = true;

    alias a = Fields!(Foo).filter!(pred); // works
    alias b = Fields!(Foo).map!(toName); // works

    alias c = Fields!(Foo).init.filter!(pred); // works
    alias d = Fields!(Foo).init.map!(toName); // Error: alias d cannot alias an
expression Fields().tuple("a")

Jun 09 2022