The Phobos Put

Ali Çehreli acehreli at yahoo.com
Wed Mar 29 15:01:27 UTC 2023


On 3/29/23 04:48, Dennis wrote:
 > On Wednesday, 29 March 2023 at 11:10:42 UTC, Salih Dincer wrote:
 >> Why does my `put` work but the Phobos `put` doesn't work with a slice?
 >
 > Your `put` doesn't take `range` by `ref`, so it allows you to pass an
 > rvalue. Consequently, it doesn't advance the range from the callers
 > perspective.

And that 'ref' is necessary because not every OutputRange can be sliced 
for further calls to put(). Salih does not have that problem because he 
is working with slices, which are (usually) trivially slicable for the 
next portion to be passed to put().

On the other hand, Phobos's put() works with any OutputRange so it has 
to take a 'ref' to advance to know where it is left off. This behavior 
makes its use with slices weird but sometimes such is life. :)

Ali



More information about the Digitalmars-d-learn mailing list