containers
containers copied to clipboard
feature request: hashset.insert(range!T inputs), i.e. add multiple elements in one call
currently, hashset can only insert one element at a time:
https://github.com/dlang-community/containers/blob/fc1625a5a0c253272b80addfb4107928495fd647/src/containers/hashset.d#L150
HashSet!string set;
set.insert("foo");
set.insert("bar");
Can we add another method, so we can insert multiple elements all at once? e.g.
set.insert(["foo", "bar", "foo"]);
Thanks.
If insert is changed to have the prototype: bool insert(scope T[] values...)
it will work as is and won't require changing.
However the return type is a bit tricky. There no way to know which values failed.
In case of HashSet
, I think this wouldn't be any more efficient than inserting them one by one.
I would suggest using each.
Maybe more useful would be to have a constructor which accepts a range, similar to assocArray.