Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a convenient syntax for invoking nested eponymous templates #19473

Open
dlangBugzillaToGithub opened this issue Aug 5, 2018 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

Yuxuan Shui (@yshui) reported this on 2018-08-05T00:13:40Z

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

CC List

  • Simen Kjaeraas

Description

Currently, given:

template A() {
    template A() {
        enum A = 1;
    }
}

This:

A!()!()

does not compile (multiple ! arguments are not allowed).

Neither does this (C style cast illegal):

(A!())!()

The only way to invoke the nested template seems to be:

alias B = A!();
B!()

This is less than ideal.
@dlangBugzillaToGithub
Copy link
Author

simen.kjaras commented on 2018-08-05T09:26:22Z

import std.meta : Instantiate;

template A() {
    template A() {
        enum A = 1;
    }
}

unittest {
    enum i = Instantiate!(A!());
}

Now, that shows it's possible in the language to work around this issue. The real issue however, is that multiple ! arguments are not allowed.

From what I can gather on the forum, the reason is a perceived ambiguity, in that F!T!int could mean F!(T!int) or (F!T)!int. The language already provides tools to disambiguate between them - the first example is how you'd invoke it that way, and the other example is simply impossible in the language right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant