Whitch can replace std::bind/boost::bind ?

Dsby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 18 09:14:13 PDT 2016


On Friday, 18 March 2016 at 11:09:37 UTC, Atila Neves wrote:
> On Friday, 18 March 2016 at 10:50:34 UTC, Dsby wrote:
>>
>> foreach (i ; 0..4) {
>> 	auto th = new Thread(delegate(){listRun(i);});//this is erro
>> 	_thread[i]= th;
>> 	th.start();
>> }
>>
>> void listRun(int i)
>> {
>>      writeln("i = ", i); // the value is not(0,1,2,3), it all 
>> is 2.
>> }
>>
>>
>> I want to know how to use it like std::bind.
>
> I would suggest not using Thread directly:
>
> foreach(i; 0..4) {
>     auto tid = spawn(&listRun, i); //from std.concurrency
>     _tid[i] = tid;
> }
>
> Atila


the listrun is in class. it is a delegate,it is not a function.


More information about the Digitalmars-d-learn mailing list