Skip to content

Passing aggregate types into templates by alias drops qualifier #17959

@dlangBugzillaToGithub

Description

@dlangBugzillaToGithub

Andrei Alexandrescu (@andralex) reported this on 2020-05-25T18:30:05Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=20863

CC List

  • Boris Carvajal
  • Adam D. Ruppe
  • John Colvin
  • Max Samukha
  • Nick Treleaven (@ntrel)
  • Steven Schveighoffer (@schveiguy)

Description

Took me a while to make this 100% self-contained. Both asserts should pass. The second fails.

alias AliasSeq(Seq...) = Seq;

template staticIndexOf(alias T, TList...)
{
    static if (TList.length == 0)
    {
        enum int staticIndexOf = -1;
    }
    else static if (is(T == TList[0]))
    {
        enum int staticIndexOf = 0;
    }
    else
    {
        private enum int t = staticIndexOf!(T, TList[1 .. $]);
        enum int staticIndexOf = t < 0 ? t : t + 1;
    }
}

struct Foo {}

static assert(staticIndexOf!(Foo, AliasSeq!(Foo)) == 0); // pass
static assert(staticIndexOf!(immutable(Foo), AliasSeq!(immutable(Foo))) == 0); // fail

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions