Get the return type of the function

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 3 11:07:02 PST 2016


On Wed, Feb 03, 2016 at 06:40:27PM +0000, xtreak via Digitalmars-d-learn wrote:
[...]
> Thanks. I was trying to get the return type of lambdas. I was trying
> the following and got an error. I was using dpaste with dmd 2.070
> 
> writeln(ReturnType!(a =(a *a)))
> 
> Error: template instance f662.main.ReturnType!((a) => a * a) does not
> match template declaration ReturnType(func...) if (func.length == 1 &&
> isCallable!func)

Not sure if this will help, but if it's possible to check the return
type inside the function, you can use typeof(return):

	auto func(float x) {
		return cast(int) x;
		static assert(is(typeof(return) == int));
	}


T

-- 
"Outlook not so good." That magic 8-ball knows everything! I'll ask about Exchange Server next. -- (Stolen from the net)


More information about the Digitalmars-d-learn mailing list