[Issue 1816] New: Parameter names not visible in return type in function declarations

downs default_357-line at yahoo.de
Tue Feb 5 04:21:01 PST 2008


d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1816
> 
>            Summary: Parameter names not visible in return type in function
>                     declarations
>            Product: D
>            Version: unspecified
>           Platform: PC
>         OS/Version: Linux
>             Status: NEW
>           Severity: normal
>           Priority: P2
>          Component: DMD
>         AssignedTo: bugzilla at digitalmars.com
>         ReportedBy: andrei at metalanguage.com
> 
> 
> The following code should compile:
> 
> typeof(a) identity(T)(T a) { return a; }
> 
> void main()
> {
>     auto x = identity(1);
> }
> 
> In this case it's trivial to replace typeof(a) with T, but in the general case
> (e.g. mixins, complex expressions) it is necessary to access parameter names in
> complex expressions inside typeof().
> 
> 
Here's a hack to work around that:

either replace your parameter names with Init!(type) where Init == template Init(T) { T Init; }

or use the return value of a delegate literal created on the spot.
Example: typeof({ T a; return operationOnA(a); }) somefunc(T)(T a) { ... }

I use that technique in scrapple.tools to say "if this string was our function body, what would its return type be?" It's fun! :D

 --downs


More information about the Digitalmars-d-bugs mailing list