Thread overview | |||||
---|---|---|---|---|---|
|
June 22, 2015 Does D has built-in stack structure? | ||||
---|---|---|---|---|
| ||||
Does D has built-in stack structure (if so, which module?) or should I implement it myself? |
June 22, 2015 Re: Does D has built-in stack structure? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Assembly | 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 Re: Does D has built-in stack structure? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adrian Matoga | 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!
|
Copyright © 1999-2021 by the D Language Foundation