why are types mismatch?

Maxim Fomin maxim at maxim-fomin.ru
Tue Oct 1 11:52:36 PDT 2013


On Tuesday, 1 October 2013 at 18:07:31 UTC, Roman wrote:
> alias int function(int) function_type;
>
>

function_type is a function pointer

> void main()
> {
> 	bar!foo(2);

foo is a function, not a function pointer

> 	bar!((int i)=> i*2)(2);
> }
>
> int foo(int i)
> {
>     return i;
> }
>
> void bar(alias baz)(int i)
> {
> 	static if (!is(typeof(baz) == function_type))
> 	{
> 		pragma(msg, typeof(baz), " != ", function_type); //wtf?
> 	}

here you are testing that baz is a function pointer

> 	std.stdio.writeln(bar(i));

you probably meant baz here

> }
>
> Where am I wrong?

Wrong at place where you mix function type and function pointer. 
You are facing

int(int i) != int function(int)
int function(int i) pure nothrow @safe != int function(int)


More information about the Digitalmars-d mailing list