Feature suggestion: in-place append to array

KF kfleszar at gmail.com
Thu Mar 4 01:02:46 PST 2010


I hope this is the right place to post it.
In my work, I often need to add elements at the end of dynamic arrays and remove them from the end. This incremental changes would most
conveniently be performed by a~=e for addition of e at the end of a, and say a=a[0..$-1]. Unfortunately, ~= always creates a copy and
is thus too time consuming. What I would like to suggest is either a new operator, ~~=, in-place append that does not create a copy if
possible. Alternatively, new properties/methods could be defined:
- a.push(element or array) - add elements at the end of the array, without copying if possible
- a.pop(x) - remove x elements from the end of the array
- a.capacity - get or set the actual length allocated for the array
Currently, I am using appender(a).put from algorithm module, but it is very obscure and makes code hard to understand.
Cheers,
KF



More information about the Digitalmars-d mailing list