Bug 16744 – We should have a TypeOf template so that typeof can be used with templates like staticMap
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-11-23T21:56:01Z
Last change time
2018-01-05T13:37:49Z
Assigned to
No Owner
Creator
Jonathan M Davis
Comments
Comment #0 by issues.dlang — 2016-11-23T21:56:01Z
Unfortunately, there is no way to do the compile-time equivalent of a lambda when dealing with templates. So, you can't use do something like
staticMap!(a => typeof(a), args)
or whatever the syntax would be if we had it. So, we need a helper template to do the same thing if we want to use typeof with something like staticMap. e.g.
staticMap!(TypeOf, args)
It seems to me that it makes sense to add such a helper to Phobos rather than requiring that everyone do it themselves when they need it.
Comment #1 by john.loughran.colvin — 2016-12-08T01:43:57Z
A more general alternative might be to (and brace yourself because you're probably not gonna like it) introduce string template lambdas.
staticMap!(`a.sizeof`, args);
staticMap!(q{typeof(a)}, args);
Comment #2 by github-bugzilla — 2017-07-29T00:52:38Z