digitalmars.D.learn - Does D has built-in stack structure?
- Assembly (2/2) Jun 21 2015 Does D has built-in stack structure (if so, which module?) or
- Adrian Matoga (12/14) Jun 22 2015 AFAIK there's no built-in, but std.array.Appender could be easily
- Assembly (2/18) Jun 22 2015 thanks!
Does D has built-in stack structure (if so, which module?) or should I implement it myself?
Jun 21 2015
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); } }
Jun 22 2015
On Monday, 22 June 2015 at 08:18:08 UTC, Adrian Matoga wrote:On Monday, 22 June 2015 at 06:09:48 UTC, Assembly wrote:thanks!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); } }
Jun 22 2015