Although there is no syntax in the language to new a static array, I think I have found a nice idiom for allocating static arrays on the GC heap (and elsewhere), using std.experimental.allocator:
import std.experimental.allocator;
void main()
{
alias T = int[4];
// T* t = new T; // Won't work.
T* t = theAllocator.make!T; // Fine!
}
In places where use of dynamic arrays are not straightforward such as in translations from other languages, this can be a practical solution.
Do you want to include this, or do you prefer a PR?
Hello, I don't have much time to update the d-idioms myself, so if you want to contribute you are welcome. Please follow the guidelines in README.md, that until now noone has ever followed.
Hi and thank you for your idioms.
Regarding https://p0nce.github.io/d-idioms/#One-does-not-simply-call-new-for-static-arrays:
Although there is no syntax in the language to new a static array, I think I have found a nice idiom for allocating static arrays on the GC heap (and elsewhere), using
std.experimental.allocator
:In places where use of dynamic arrays are not straightforward such as in translations from other languages, this can be a practical solution.
Do you want to include this, or do you prefer a PR?
Cheers, Bastiaan.