Referencer
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Mon Nov 23 04:09:11 PST 2015
On Monday, 23 November 2015 at 11:31:32 UTC, HaraldZealot wrote:
> On Friday, 20 November 2015 at 19:53:23 UTC, HaraldZealot wrote:
>> On Friday, 20 November 2015 at 18:48:51 UTC, Alex Parrill
>> wrote:
>>> On Friday, 20 November 2015 at 18:23:57 UTC, HaraldZealot
>>> wrote:
>>>
>>> You say ranges are pass-by-value, but that's not entirely
>>> true. Ranges themselves can be classes, or be made references
>>> via std.range.refRange. Range elements can be made lvalues by
>>> using ref functions [1].
>>
>> Possible refRange is what I was looking for. Thanks.
>>
>
> Unfortunately current RefRange and refRange implementation
> doesn't work with out-range :( Ridiculous, because reference
> semantic for out-range even is more important.
>
> So I'm found myself at fork point which from my next work for
> community is better:
>
> * add support for out range in `RefRange`
> * or implement further my universal referencer?
RefRange is not intended to work with output ranges, and output
ranges are very different beasts from input ranges, so any kind
of reference type wrapper for output ranges should be a separate
construct. That being said, I'd be inclined to argue that
anything taking an output range should always take it by ref,
precisely because copying an output range almost never results in
the correct semantics. So, we should probably make it a general
policy that anything accepting an output range should accept it
by ref.
Now, if you need to work around the fact that a function doesn't
take its arguments by ref, you could probably just pass a pointer
to your output range rather than passing it by value. The syntax
of calling a function on a pointer is the same as calling it on
the object directly, so it should just work. And if it doesn't
for some reason, then given the fact that the only function that
output ranges recognize is put, creating a reference type wrapper
would be pretty trivial; you only have one function to worry
about. Certainly, I would think that your Referencer type is
going in the wrong direction, because it's declaring a bunch of
functions that have nothing to do with output ranges.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list