Transforming a range back to the original type?

Steven Schveighoffer schveiguy at yahoo.com
Fri May 4 05:49:35 PDT 2012


On Thu, 03 May 2012 04:41:50 -0400, Jacob Carlborg <doob at me.com> wrote:

> On 2012-05-02 23:40, Jonathan M Davis wrote:
>> On Wednesday, May 02, 2012 23:01:21 Jacob Carlborg wrote:
>>> Is there a general function for transforming a range back to the
>>> original type? If not, would it be possible to create one?
>>
>> You mean that if you have something like
>>
>> auto range = getRangeFromSomewhere();
>> auto newRange = find(filter!func(range), value);
>>
>> you want to transform newRange back to the same type as range?
>
> No, I want to transform newRange back to a collection, the same type as  
> the original collection. I was thinking something like this:
>
> Collection c = new Collection();
> c = c.filter!(x => x < 3).toCollection();

Why can't the last line be:

c = new Collection(c.filter!(x => x < 3));

or more generically:

c = new typeof(c)(c.filter!(x => x < 3));

?

-Steve


More information about the Digitalmars-d-learn mailing list