1 module auxil.treepath; 2 3 struct TreePath 4 { 5 import std.experimental.allocator.mallocator : Mallocator; 6 import automem.vector : Vector; 7 8 @safe: 9 10 Vector!(int, Mallocator) value; 11 12 @disable this(this); 13 14 this(ref return scope TreePath rhs) nothrow @trusted 15 { 16 value = rhs.value[]; 17 } 18 19 this(ref return scope const(TreePath) rhs) nothrow @trusted const 20 { 21 value = rhs.value[]; 22 } 23 24 this(ref return scope inout(TreePath) rhs) nothrow @trusted inout 25 { 26 // // value = typeof(this)(rhs.value[]); 27 // size_t l = rhs.value.length(); 28 // (cast(const)value).length = l; 29 auto dummy = Vector!(int, Mallocator)(cast(int[])rhs.value[]); 30 value = cast(inout) dummy; 31 } 32 33 ref int back() return @nogc 34 { 35 assert(value.length); 36 return value[$-1]; 37 } 38 39 void popBack() @nogc 40 { 41 value.popBack; 42 } 43 44 void clear() @nogc 45 { 46 value.clear; 47 } 48 49 auto put(int i) @nogc @trusted 50 { 51 value.put(i); 52 } 53 54 import std.range : isOutputRange; 55 import std.format : FormatSpec; 56 57 void toString(Writer) (ref Writer w, scope const ref FormatSpec!char fmt) const @trusted 58 if (isOutputRange!(Writer, char)) 59 { 60 import std; 61 import std.conv : text; 62 63 w.put('['); 64 if (value.length) 65 { 66 foreach(e; value[0..$-1]) 67 copy(text(e, "."), w); 68 copy(text(value[$-1]), w); 69 } 70 w.put(']'); 71 } 72 }