Thread overview
Does D has built-in stack structure?
Jun 22, 2015
Assembly
Jun 22, 2015
Adrian Matoga
Jun 22, 2015
Assembly
June 22, 2015
Does D has built-in stack structure (if so, which module?) or should I implement it myself?
June 22, 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); }
}

June 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:
>> 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); }
> }

thanks!