templated lambda with {} cause GC
Simen Kjærås
simen.kjaras at gmail.com
Fri Aug 10 10:38:53 UTC 2018
On Friday, 10 August 2018 at 09:57:53 UTC, learnfirst1 wrote:
> T!(t => {
> printf("test 2 name = %s\n".ptr, t.name.ptr);
> }, "test") ; // build error
This is not doing what you think it's doing. The syntax t => {
return t; } is equivalent to t => () => t. That is, it's
returning a function that takes no arguments, not a value.
For that very same reason, if you compile and run your code
without -betterC, only the first printf() will be executed, and
only one line of output will be generated.
What you should do instead is:
T!((t){
printf("test 2 name = %s\n".ptr, t.name.ptr);
}, "test");
(note the lack of the => arrow)
--
Simen
More information about the Digitalmars-d-learn
mailing list