Issue with forward ranges which are reference types

Steven Schveighoffer schveiguy at yahoo.com
Wed Aug 17 19:37:45 PDT 2011


On Wed, 17 Aug 2011 22:36:14 -0400, Mehrdad <wfunction at hotmail.com> wrote:

> On 8/17/2011 8:26 AM, Steven Schveighoffer wrote:
>> On Wed, 17 Aug 2011 10:56:02 -0400, Mehrdad <wfunction at hotmail.com>  
>> wrote:
>>
>>> On 8/17/2011 7:14 AM, Steven Schveighoffer wrote:
>>>> Casting is actually the correct solution.
>>>>
>>>> if(auto irange = cast(InputRangeObject)collection)
>>>> {
>>>>    // now you can use irange
>>>>    if(collection.empty) // success!
>>>>    {
>>>>       ...
>>>>    }
>>>> }
>>> The correct solution? It doesn't even compile. (See my last post,  
>>> which was after the one you replied to.)
>>
>> Oh, right, InputRangeObject is a template.  Sorry, I forgot about that  
>> aspect.
>>
>> So actually, that isn't possible if you are returning Object, you need  
>> to return the correct InputRange(T) type.
>>
>> (in this case InputRange!int)
>>
>> Another good reason to avoid class-based ranges :)
>>
>> -Steve
> Er, if they aren't supported then please just remove them altogether...  
> hasn't that been the philosophy so far?

It's not my call.  My opinion differs from the others, especially Andrei.

-Steve


More information about the Digitalmars-d mailing list