Don't use arrays as stacks

Nick Sabalausky a at a.a
Mon Sep 26 23:12:47 PDT 2011


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:j5rn5o$1q0g$1 at digitalmars.com...
> 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).
>

Umm, maybe. Sounds like it should be feasable, though I haven't tried. 
Although going by what Steve said about assumeSafeAppend, it might actually 
end up slower than a wrapped Stack type that doesn't use assumeSafeAppend.




More information about the Digitalmars-d mailing list