Test the return type of 'unaryFun' and 'binaryFun'.

Mek101 oidgemek101 at gmail.com
Thu Aug 29 08:58:18 UTC 2019

As the title says, is there a way to test the return type of the 
'unaryFun' and 'binaryFun' templates from 'std.functional'?

I have the following code, and I want to to be sure that 
'predicate' returns a boolean, but neither 'is(typeof(predicate) 
== bool)' or 'is(ReturnType!predicate == bool)' seem to work.

>private alias NullSized = Nullable!(size_t, size_t.max);

>public NullSized indexOf(alias pred = "a == b", Range, V)(Range 
>array, V value)
>if((isRandomAccessRange!Range || isStaticArray!Range))
>	alias predicate = binaryFun!pred;
>	for(size_t i = 0; i < array.length; i++)
>		if(predicate(array[i], value))
>			return NullSized(i);
>	return NullSized.init;

More information about the Digitalmars-d-learn mailing list