digitalmars.D.learn - Getting template parameters by its name
- Yui Hosaka (29/29) Jan 10 2019 I want to do something like this:
- Paul Backus (4/13) Jan 10 2019 You can get the arguments of a template instance as an AliasSeq
- Yui Hosaka (2/17) Jan 11 2019 It seems a good choice to me. Thank you!
I want to do something like this: ---- template S(T) { } void main() { pragma(msg, S!(int).T); // Error: no property `T` for type `void` } ---- Using alias, it is possible to get T by another name: ---- template S(T) { alias t = T; } void main() { pragma(msg, S!(int).t); } ---- But the same identifier cannot be used: ---- template S(T) { alias T = T; // Error: `alias T = T;` cannot alias itself, use a qualified name to create an overload set } void main() { pragma(msg, S!(int).T); } ---- Is there any nice way that `S!(int).T` works?
Jan 10 2019
On Friday, 11 January 2019 at 04:59:50 UTC, Yui Hosaka wrote:I want to do something like this: ---- template S(T) { } void main() { pragma(msg, S!(int).T); // Error: no property `T` for type `void` } ----You can get the arguments of a template instance as an AliasSeq using `std.traits.TemplateArgsOf`. https://dlang.org/phobos/std_traits.html#TemplateArgsOf
Jan 10 2019
On Friday, 11 January 2019 at 06:13:11 UTC, Paul Backus wrote:On Friday, 11 January 2019 at 04:59:50 UTC, Yui Hosaka wrote:It seems a good choice to me. Thank you!I want to do something like this: ---- template S(T) { } void main() { pragma(msg, S!(int).T); // Error: no property `T` for type `void` } ----You can get the arguments of a template instance as an AliasSeq using `std.traits.TemplateArgsOf`. https://dlang.org/phobos/std_traits.html#TemplateArgsOf
Jan 11 2019