Don't use arrays as stacks

bearophile bearophileHUGS at lycos.com
Sun Sep 25 04:42:39 PDT 2011


Nick Sabalausky:

> https://www.semitwist.com/articles/article/view/don-t-use-arrays-as-stacks

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