Capturing by value in the thread

Kagamin spam at here.lot
Fri Oct 18 20:48:47 UTC 2024


this works for me
```
void aa()
{
	void delegate()[] items;

	auto captureFuction(int index)
	{
		return (){
			auto localIndex = index;
			writeln("index: ", localIndex);
		};
	}

	for(int i = 0; i < 10; i++)
	{
		auto work = captureFuction(i);
		items ~= work;
	}

	foreach(worker; items)
	{
		worker();
	}
}
int main()
{
     aa();
     return 0;
}
```


More information about the Digitalmars-d-learn mailing list