Rust-like collect in D
Nordlöw via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 6 10:31:11 PDT 2016
On Thursday, 6 October 2016 at 17:22:10 UTC, Dicebot wrote:
> On Thursday, 6 October 2016 at 16:56:26 UTC, Nordlöw wrote:
>> Is there a way to do this, or do we need something similar to
>> `collect` in Phobos? Something like
>>
>> import std.container.array : Array;
>>
>> 0.iota(n).collect!Array
>
> You mean semantics like this?
>
> Container collect(Container, Range) (Range r)
> if(isOutputRange!Container)
> {
> Container container;
> r.copy(container);
> return container;
> }
Yes, along with inference of element type of the container.
More information about the Digitalmars-d-learn
mailing list