Eigenpoll : D wish list : Array pushback/popback 

Automatic 'pushback' and 'popback' in arrays

Several hundred times I wrote in C++ something like this:

vector v;
v.push_back( xyz );
abc = v.pop_back();

D would be better, if it could support this feature in the core language like this:

int[] a;

a[!] = 77; // a[!] writing means "pushback"
int x = a[!]; // a[!] reading means "popback"

Which would be the same as:

a.length = a.length + 1;
a[length-1] = 77;
int x = a[length-1];
a.length = a.length - 1;

With this super-compact addition D would be so powerful even in the core language, that there would be in many cases no need for complicated STL like containers!

Report this item for cleanup