std.collection lets rename it into std,ridiculous.

James Miller james at aatch.net
Sun Feb 19 21:30:43 PST 2012


On 20 February 2012 16:43, H. S. Teoh <hsteoh at quickfur.ath.cx> wrote:
> On Mon, Feb 20, 2012 at 04:19:10PM +1300, James Miller wrote:
> [...]
>> My feedback is that for most people's purposes, associative arrays and
>> arrays (dynamic and static) are fine. PHP doesn't have a well-used
>> collections library (though it does exist) but it is used by millions
>> of sites every day. I don't normally need an explicit
>> queue/stack/priority queue.
> [...]
>
> The convenience and flexibility of D's arrays have, for the most part,
> replaced my need for explicit stacks or queues. For example, here's a
> stack:
>
>        T[] stack;
>        void push(elem) {
>                stack ~= elem;
>        }
>        T pop() {
>                T elem = stack[$-1];
>                stack = stack[0..$-1];
>                return elem;
>        }
>
> Here's a queue:
>
>        T[] queue;
>        void enqueue(elem) {
>                queue ~= elem;
>        }
>        T dequeue() {
>                T elem = queue[0];
>                queue = queue[1..$];
>                return elem;
>        }
>
> It's so trivial to implement that it's hardly worth the effort to
> implement a class for it.
>
> Your mileage may vary, though.
>
>
> T

The cool thing about that implementation is that, by using slices, you
generally avoid allocation, unless its neccessary.


More information about the Digitalmars-d mailing list