Get return type statically
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 27 20:13:21 PDT 2016
On Tue, Jun 28, 2016 at 01:41:03AM +0000, Smoke Adams via Digitalmars-d-learn wrote:
> I have a type
>
> public class SuperFunction(T)
> {
> T t;
> return(T) Do() { return t(); }
> }
>
> where T is a delegate or function. First, I would like to be able to
> specify that this must be the case for SuperFunction so we can't pass
> non-function/delegates for T.
Try:
class SuperFunction(T)
if (is(T == function) || is(T == delegate))
{
...
}
> Second, How to specify the return type of Do to match that of T.
Maybe this?
import std.traits : ReturnType, Parameters;
ReturnType!T Do(Parameters!T args) { return t(args); }
T
--
INTEL = Only half of "intelligence".
More information about the Digitalmars-d-learn
mailing list