I'd like to create an empty heap, and then add to it an arbitrary (and statically unknown) number of items, keeping the heap invariant valid all the time (this means the heap invariant is valid after each item is added to the heap, so I am free to pop items in any moment). Is this possible with std.container.BinaryHeap? If this is not possible then I think this is a common and really basic operation that needs to be possible. If it's already possible, then I suggest to add a little example to the std.container.BinaryHeap module docs that shows how you do it.
import std.container.binaryheap; import std.container.array; import std.random; void main() { BinaryHeap!(Array!uint) heap; uint n = uniform(100, 2000); foreach (_;0..n) heap.insert(uniform(0,uint.max)); } I didn't get it to work with uint[], perhaps there's a bug. It kept saying "Cannot grow a heap created over a range," but as you can see, it should work with uint[] as the following static if should evaluate to true. https://github.com/dlang/phobos/blob/master/std/container/binaryheap.d#L279
Using the method insert as pointed out in comment 2 is the way to go. Closing as invalid.