Bug 24080 – std.traits.TemplateOf doesn't return void for non-template functions

Status
NEW
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-08-10T21:00:11Z
Last change time
2024-12-01T16:41:37Z
Assigned to
No Owner
Creator
Steven Schveighoffer
See also
https://issues.dlang.org/show_bug.cgi?id=18214
Moved to GitHub: phobos#10527 →

Comments

Comment #0 by schveiguy — 2023-08-10T21:00:11Z
std.traits.TemplateOf resolves to `void` on non-template types. However, it fails to compile on non-template functions: ```d struct S {} void foo() {} pragma(msg, TemplateOf!S); // void pragma(msg, TemplateOf!foo); // error ``` The reason is because the `TemplateOf` overloads only include a catch-all for types: ```d alias TemplateOf(T) = void; ``` If we change the parameter to an `alias`, it works for both types and functions. I believe the reason this wasn't "solved" before might be because of the problem with passing basic types to alias parameters. However, this has been solved since 2.087: https://dlang.org/changelog/2.087.0.html#template_alias_matches_basic_types In fact, I think we can remove the overload that specifically matches template types as well, and just have two aliases: ```d alias TemplateOf(alias T : Base!Args, alias Base, Args...) = Base; alias TemplateOf(alias T) = void; ```
Comment #1 by robert.schadek — 2024-12-01T16:41:37Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10527 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB