std.traits.ReturnType b0rking on function pointer.

Kirk McDonald kirklin.mcdonald at gmail.com
Wed Jan 17 11:52:49 PST 2007


Daniel Keep wrote:
> 
> Hey there, I'm having problems with getting the return type of a 
> function pointer.  Basically, I want to do this:
> 
> template SDL_SafeCall(alias tFn)
> {
>     ReturnType!(SDL_SetVideoMode) SDL_SafeCall(...)
>     {
>         ...
>     }
> }
> SDL_SafeCall!(SDL_SetVideoMode)(...);
> 
> where SDL_SetVideoMode is declared like so (yes, it's DerelictSDL):
> 
> typedef SDL_Surface* function(int,int,int,Uint32) pfSDL_SetVideoMode;
> pfSDL_SetVideoMode          SDL_SetVideoMode;
> 
> When I try to compile my code, I get the following errors:
> 
> C:\Daniel\dmd\dmd\src\phobos\std\traits.d(34): alias 
> std.traits.ReturnType!(pfSDL_SetVideoMode).ReturnType recursive alias 
> declaration
> C:\Daniel\dmd\dmd\src\phobos\std\traits.d(34): template instance 
> std.traits.ReturnType!(pfSDL_SetVideoMode) error instantiating
> 
> I've tried writing my own version, but that didn't do any better. Anyone 
> have any ideas?
> 
>     -- Daniel

ReturnType has two forms: One which is intended to operate on a function 
pointer or delegate /type/, and one which is intended to operate on a 
function alias.

SDL_SetVideoMode is a function pointer. You want to pass its /type/ to 
ReturnType. By passing it directly, it gets sent to the alias form of 
ReturnType, which confuses it greatly. Try this:

ReturnType!(typeof(SDL_SetVideoMode))

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org


More information about the Digitalmars-d-learn mailing list