Don't use arrays as stacks
bearophile
bearophileHUGS at lycos.com
Mon Sep 26 22:32:40 PDT 2011
Nick Sabalausky:
> Not that slicing a stack would be all that common, but if it were done for
> whatever reason...
Is it possible to write a function like:
ForeachType!A unsafePop(A)(A)if(isDynamicArray!A) { /*...*/ }
that contains both the popping (and something like assumeSafeAppend to mess with the druntime data structures) and use it to allow a stack-like usage of D dynamic arrays? (This function is not meant to replace the usage of a proper stack data structure based on a deque when you need a heavy-duty stack, but it's handy in other lighter cases).
Bye,
bearophile
More information about the Digitalmars-d
mailing list