Bug 19139 – Need a convenient syntax for invoking nested eponymous templates

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-08-05T00:13:40Z
Last change time
2024-12-13T19:00:06Z
Assigned to
No Owner
Creator
Yuxuan Shui
Moved to GitHub: dmd#19473 →

Comments

Comment #0 by yshuiv7 — 2018-08-05T00:13:40Z
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.
Comment #1 by simen.kjaras — 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.
Comment #2 by robert.schadek — 2024-12-13T19:00:06Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19473 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB