1 module nxt.minimal_fixed_array; 2 3 @safe: 4 5 /** Minimalistic fixed-length (static) array of (`capacity`) number of elements 6 * of type `E` where length only fits in an `ubyte` for compact packing. 7 */ 8 struct MinimalFixedArray(E, ubyte capacity) 9 { 10 @safe: 11 12 this(in E[] es) 13 { 14 assert(es.length <= capacity, 15 "Length of input parameter `es` is larger than capacity " 16 ~ capacity.stringof); 17 _es[0 .. es.length] = es; 18 _length = cast(typeof(_length))es.length; 19 } 20 21 private: 22 E[capacity] _es; 23 typeof(capacity) _length; 24 } 25 26 @safe pure nothrow @nogc unittest 27 { 28 const ch7 = MinimalFixedArray!(char, 7)(`1234567`); 29 assert(ch7._es[] == `1234567`); 30 }