Re: Capturing by value in the thread

2024-10-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 18 October 2024 at 12:07:24 UTC, Kadir Erdem Demir wrote: It seems [=] functionality C++ does not exist in D. No, D does not have this functionality. By using a helper function I made that example work. ```d import std.stdio; auto localFoo(int x) { return (){ return x;}; }

Re: Capturing by value in the thread

2024-10-18 Thread mzfhhhh via Digitalmars-d-learn
On Friday, 18 October 2024 at 12:07:24 UTC, Kadir Erdem Demir wrote: It seems [=] functionality C++ does not exist in D. By using a helper function I made that example work. [...] Because 'work' is captured, it is allocated on the heap. The loops are all assigning values to this 'work' in the

Re: Capturing by value in the thread

2024-10-18 Thread Kagamin via Digitalmars-d-learn
this works for me ``` void aa() { void delegate()[] items; auto captureFuction(int index) { return (){ auto localIndex = index; writeln("index: ", localIndex); }; } for(int i =

Capturing by value in the thread

2024-10-18 Thread Kadir Erdem Demir via Digitalmars-d-learn
It seems [=] functionality C++ does not exist in D. By using a helper function I made that example work. ```d import std.stdio; auto localFoo(int x) { return (){ return x;}; } void main() { int x = 10; auto lambda = (int capturedX = x) { writeln("Captured reference : ", ca