Referencer

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 23 07:35:29 PST 2015


On Monday, 23 November 2015 at 14:25:19 UTC, HaraldZealot wrote:
> On Monday, 23 November 2015 at 12:09:13 UTC, Jonathan M Davis 
> wrote:
>> On Monday, 23 November 2015 at 11:31:32 UTC, HaraldZealot 
>> wrote:
>>
>> 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.
>
> So, you see that to open a PR about changes _by value_ to _by 
> ref_ semantic for all functions operate with out range 
> (especially for copy) is better way? But this breaks existing 
> API...

That would require a larger discussion. It's come up before, but 
I don't recall if anything was ever decided. Output ranges pretty 
much have to be reference types or be passed by ref to work 
properly though. Pseudo-reference types might work under some 
circumstances (e.g. dynamic arrays), but outright value types 
won't. So, we almost have to make it so that they're passed by 
ref in order for them to work. But output ranges probably are 
long past due for a more in-depth discussion of their problems 
and how we should address them (e.g. how is code supposed to deal 
with the possibility of the output range being full) - though at 
this point, we're mostly trying to move to using lazy input 
ranges in most cases, since they're more flexible, and that will 
limit the scope of output ranges and make their deficiencies less 
of an issue (though we really should fix them).

In any case, no, you probably shouldn't just start creating PRs 
which put ref on various output range parameters in Phobos.

>> 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.
>
> I see my referencer as universal wrapper to any value-like 
> stuff (e.g. structs or even simple POD variable), not only for 
> out ranges (or input ranges). But possibly it is to general 
> (and so not perfect) solution.

Well, if all you want is to get a reference type out of a value 
type, then putting it on the heap and using a pointer to it would 
be a solution. Using RefCounted would be another, and I would 
think that it would be similar to what you're trying to do, since 
what you're trying to do sounds like it would be something like a 
RefCounted that doesn't actually involve reference counting.

- Jonathan M Davis


More information about the Digitalmars-d mailing list