store template value

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 1 14:22:28 PDT 2015


On 08/01/2015 08:37 AM, maarten van damme via Digitalmars-d-learn wrote:
> I have a class that creates a task in it's constructor. How do I store this
> created task as one of it's value members and later on call .yieldForce()?
>

Tasks can be created with a function pointer 'function parameter' as 
well. (This has already been added to "Programming in D" but it is not 
available on the web site yet.)

I learned the exact type by the help of pragma(msg) below and used it to 
create MyTask and myTasks:

import std.parallelism;

double foo(int i)
{
     return i * 1.5;
}

double bar(int i)
{
     return i * 2.5;
}

void main()
{
     auto tasks = [ task(&foo, 1),
                    task(&bar, 2) ];    // ← compiles

     pragma(msg, typeof(tasks[0]));

     alias MyTask = Task!(run, double function(int), int)*;

     MyTask[] myTasks;
     myTasks ~= task(&foo, 1);
     myTasks ~= task(&bar, 2);
}

Ali



More information about the Digitalmars-d-learn mailing list