Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.small_array

Small Array

The module contains self-contained generic small array implementaton.
SmallArray supports ASDF - Json Serialisation Library.
Authors:
Ilya Yaroshenko
struct SmallArray(T, uint maxLength) if (maxLength);
Examples:
SmallArray!(char, 16) s16;
assert(!s16);

auto s8 = SmallArray!(char, 8)("Hellow!!");
assert(s8);
assert(s8 == "Hellow!!", s8[]);

s16 = s8;
assert(s16 == "Hellow!!", s16);
s16[7] = '@';
s8 = null;
assert(!s8);
assert(s8 == null);
assert(s8 !is null);
s8 = s16;
assert(s8 == "Hellow!@");

auto s8_2 = s8;
assert(s8_2 == "Hellow!@");
assert(s8_2 == s8);

assert(s8 < "Hey");
assert(s8 > "Hellow!");

assert(s8.opCmp("Hey") < 0);
assert(s8.opCmp(s8) == 0);
Examples:
Concatenation
auto a = SmallArray!(char, 16)("asdf");
a ~= " ";
auto b = a ~ "qwerty";
static assert(is(typeof(b) == SmallArray!(char, 16)));
assert(b == "asdf qwerty");
b.put('!');
b.put("!");
assert(b == "asdf qwerty!!");
this(typeof(null));

this(V[] array);

this(uint n)(SmallArray!(T, n) array);

this(uint n)(ref SmallArray!(T, n) array);

this(Range)(auto ref Range array)
if (isIterable!Range);
Constructor
ref typeof(this) opAssign(typeof(null)) return;

ref @trusted typeof(this) opAssign(V[] array) return;

ref typeof(this) opAssign(ref SmallArray rhs) return;

ref typeof(this) opAssign(SmallArray rhs) return;

ref typeof(this) opAssign(uint n)(ref SmallArray!(T, n) rhs) return
if (n != maxLength);

ref typeof(this) opAssign(uint n)(SmallArray!(T, n) rhs) return
if (n != maxLength);
= operator
ref typeof(this) append(T elem);
ref typeof(this) append(V[] array);

alias put = append;

template opOpAssign(string op : "~")
const scope SmallArray concat(V[] array);

template opBinary(string op : "~")
inout @property @trusted inout(T)[] asArray() return;
Returns an scope common array.
The property is used as common array representation self alias.
The alias helps with [], [i], [i .. j], ==, and != operations and implicit conversion to strings.
bool opCast(T : bool)();
Checks if the array is empty (null).
size_t toHash();

auto opCmp()(V[] array);
Hash implementation