I have a custom Buf struct (working as a simple vector)
struct Buf(T) {
size_t cap, len;
T *data;
@nogc
this(T[] arr) {
reserve(arr.length);
foreach(item; arr) {
push(item);
}
}
...
};
And I have a function like this:
void test(Buf!(int) buf) {
}
I want to be able to make it work array-like to have compact
function calls.
Something like this:
test([1,2,3]);
Currently I have the constructor shown and with that I do:
test(Buf!(int)([1,2,3]);
which is compact but can it be done differently? Meaning, if a
function takes
a Buf!(T), can it also take a T[] and construct a Buf!(T) using
some constructor?
Thanks in advance!