Make std.container.Array an output range
Rene Zwanenburg via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 5 10:48:28 PDT 2014
On Thursday, 5 June 2014 at 16:29:09 UTC, monarch_dodra wrote:
> On Thursday, 5 June 2014 at 16:21:21 UTC, monarch_dodra wrote:
>> Well, one issue is that for a "Range", "put" really just means
>> overwrite the front element, and pop it. So...
I see. I wasn't aware of that.
> That said, having an explicit OutputRange adapator:
>
> struct BackInserter(Container)
> {
> Container* c;
> void put(T)(ref T t)
> {
> c.insertBack(t);
> }
> }
> auto backInserter(Container)(ref Container c)
> {
> return BackInserter!Container(&c);
> }
>
>
> Useage:
> inputRange.copy(someArray.backInserter());
>
> There: Clear and un-ambiguous.
Agreed. This is much nicer.
>>> Should I file an enhancement request or is there something
>>> fundamentally wrong with this idea? For Array it should be as
>>> simple as adding
>>>
>>> alias doPut = insertBack;
>
> doPut is not a range primitive. Implementing "doPut" on your
> container should have no effect. If it does, it is a bug and
> will *quickly* be fixed. Don't count on it working.
>
> The correct primitive is "put".
Thanks. I skimmed the documentation for std.range.put a bit too
fast :). Reading it more carefully I see it also mentions your
first point regarding front + popFront.
More information about the Digitalmars-d
mailing list