Why after writeln the binaryHeap become empty?
lili
akozhao at tencent.com
Wed Jun 19 04:27:46 UTC 2019
On Tuesday, 18 June 2019 at 17:25:51 UTC, Johannes Loher wrote:
> The result of heapify is a BinaryHeap, which is a range. writeln
> basically prints ranges by iterating over them and printing
> each element
> (except for the types which are special cased, such as dynamic
> arrays
> etc.). However, ranges are consumed by iterating over them,
> which
> explains the behavior because writeln is not special cased for
> BinaryHeaps.
>
> Funnily enough, BinaryHeap does not implement a "save" method,
> which is the usual way of making ranges copiable, i.e. making
> them ForwardRanges. In this case I believe save could even
> simply be an alias to dup.
Do you known reason for why Dlang Range are consumed by iterating
over them. I this design is strange.
More information about the Digitalmars-d-learn
mailing list