[Issue 23174] New: Can't alias tuple when it's part of dot expression following a struct literal

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 9 08:31:10 UTC 2022


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

          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 at puremagic.com
          Reporter: boris2.9 at 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")
}

--


More information about the Digitalmars-d-bugs mailing list