On Tuesday, June 18, 2019 10:27:46 PM MDT lili via Digitalmars-d-learn wrote: > 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.
If you want an overview of ranges, you can watch this: https://www.youtube.com/watch?v=A8Btr8TPJ8c You can also read this: http://ddili.org/ders/d.en/ranges.html - Jonathan M Davis