On Monday, 22 June 2015 at 06:09:48 UTC, Assembly wrote:
Does D has built-in stack structure (if so, which module?) or should I implement it myself?

AFAIK there's no built-in, but std.array.Appender could be easily wrapped in an interface that makes thinking of it as stack easier:

struct Stack(T)
{
        import std.array: Appender, appender;
        Appender!(T[]) _app;
        @property ref inout(T) top() inout { return _app.data[$ - 1]; };
        @property bool empty() const { return _app.data.length == 0; }
        void pop() { _app.shrinkTo(_app.data.length - 1); }
        void push(T t) { _app.put(t); }
}

Reply via email to