Summary: toDelegate handles only a tiny subset of function
                    pointer types
           Product: D
           Version: 2.041
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD

--- Comment #0 from Max Samukha <> 2010-03-08 23:33:42 
PST ---
Current implementation of toDelegate requires parameter and return types of the
argument to be accessible from std.functional, meaning that it won't accept
most of function pointers taking or returning instances of UDTs:

import std.functional;

struct S

void foo(S s)

void main()
    auto dg = &toDelegate(&foo);

Error: identifier 'S' is not defined

The cause is the mixed-in delegate type generated from the function pointer
type's stringof, which is invalid in the context of the template declaration.
A workaround is to avoid the stringof like this:

alias ParameterTypeTuple!(F) Params;
// mixed-in string:
alias <storage classes> ReturnType!(F) delegate(<storage classes> Params[0],
... <storage classes> Params[$ - 1]) Dg;

where <storage classes> are extracted from F's stringof (isRef, isOut, isLazy
may work too)

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to