Managing temporaries

I’ve been told that C++ can now manage temporary matrices in loops automatically. For instance,

for (...) {
      // create B, D
      K += B' * D * B * Jw

would apparently allocate temporaries only once, before the loop starts.

If this is actually true, what are the chances Julia will have something similar?


There is AutoPreallocation.jl, Alloc.jl and PreallocationTools for helping writing non-allocating function/loops, although development for the first 2 has slowed down a bit (most recent commits in 2020). Would be nice to see it in the main language though. For use with differential equations, the ModelingToolkit.jl may also help with allocations somewhat automatically