how to make interface with return auto

Andrea Fontana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 3 06:19:05 PDT 2017


On Monday, 3 April 2017 at 12:42:02 UTC, Eko Wahyudin wrote:
> I know it's imposible.
>
> is there's a way if i want to create an interface that have 
> method with return type value is equals with return type of 
> std.palallelism.task
>
> eg.
> interface IWorker{
>    auto activate(); //on implementation class activate return 
> std.parallelism.task
> }
>
> What is the replacement of auto on that interface?
>
> Thank you!

You want to use ReturnType from std.traits.

task() is a template function so you have to define its template 
params or do a template interface, i guess.

#1:

void f() {
}

interface IWorker{
    ReturnType!(task!f) activate(); //on implementation class 
activate return std.parallelism.task
}

#2:

interface IWorker(T, Args...){
    ReturnType!(task!(T, Args)) activate(); //on implementation 
class activate return std.parallelism.task
}


Andrea


More information about the Digitalmars-d-learn mailing list