On Friday, 22 January 2016 at 01:49:58 UTC, anonymous wrote:
On 22.01.2016 01:49, W.J. wrote:
How can I identify those ranges, or, how can I tell if any
particular
range has value semantics ? I didn't read any of this in the
manual -
not that I could remember anyways.
Generally you shouldn't. If you care about it either way, use
.save or std.range.refRange.
If you don't want some range r to be consumed by some
operation, pass r.save instead of plain r. If you want r to be
consumed, pass refRange(&r). Only if you don't care if r is
consumed or not, should you pass simply r.
If you know for a fact that copying r is the same as r.save,
then you can just pass (and copy) r, of course. We know it's
that way with dynamic arrays, because of their nature as
pointer+length structures. But there's nothing wrong with
calling .save on an array anyway.
Also, when a function takes a range via a ref parameter, then
you don't need refRange, of course. The ref parameter ensures
that no copy is made and that the original range is affected by
the function.
This is even better than trying to figure out whether value
semantics are supported or not.
So, .safe returns a copy of the range - I suppose a copy of the
current state - and refRange always consumes the values in the
range.
Thanks a lot for your reply! Very much appreciated.